Finding Element Index in Array with Python

🚀 Day 45 of #100DaysOfCode — Finding the Index of an Element in an Array Hey everyone! 👋 Today’s challenge focused on searching for an element in an array and returning its index. If the element doesn’t exist, we return -1 — simple but fundamental logic 💡 👨💻 What I practiced today: ✅ Implementing a linear search ✅ Iterating through arrays using loops ✅ Handling “not found” cases gracefully ✅ Writing clean and readable Python functions 📌 Today's Task: ✔ Create a function findIndex(arr, element) ✔ Return the index of the given element ✔ Return -1 if the element is not present 🧠 Example: Input: [1, 2, 3], 2 Output: 1 Input: ["a", "b", "c"], "c" Output: 2 Input: [5, 8, 10], 3 Output: -1 💡 Key Takeaway: A simple loop can solve many problems efficiently. Linear search is easy to understand and works well for small to medium datasets. #100DaysOfCode #Python #Arrays #Programming #ProblemSolving #LearningToCode #CodingJourney #Day45

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories