🚀 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
Finding Element Index in Array with Python
More Relevant Posts
-
🚀 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
To view or add a comment, sign in
-
-
🚀 Day 19: Python Range Deep Dive Today is all about the power of the range() function! It’s not just for loops; it’s a memory-efficient sequence generator. Key takeaways: ✅ Custom Steps: Use range(start, stop, step) to skip numbers ✅ Smart Membership: Use in to instantly check if a number fits the sequence logic ✅ Efficient Length: len() tells you the count without expanding the list x = range(3, 10, 2) print(list(x)) # Output: [3, 5, 7, 9] r = range(0, 10, 2) print(6 in r) # Output: True print(7 in r) # Output: False print(len(r)) # Output: 5 Small steps every day lead to big results in 2026! 💻✨ Stay tuned for more!!! #Python #PythonJourney #Coding #LearnToCode #Programming #PythonCode #DataAnalyst #DataAnalytics #RangeFunction
To view or add a comment, sign in
-
🚀 Day 47 of #100DaysOfCode — Extracting Odd Numbers from an Array Hey everyone! 👋 Today’s challenge was about filtering elements in an array and returning a new array that contains only odd numbers. 👨💻 What I practiced today: ✅ Iterating through arrays efficiently ✅ Using conditional logic (% operator) ✅ Building a new array based on conditions ✅ Writing clean and readable Python functions 📌 Today's Task: ✔ Create a function getOdds(arr) ✔ Extract only odd numbers from the array ✔ Return a new array with the result 🧠 Example: Input: [1, 2, 3, 4, 5] Output: [1, 3, 5] Input: [2, 4, 6] Output: [] 💡 Key Takeaway: Filtering data is a core programming skill. Simple conditions combined with loops can help extract exactly what you need from a dataset. #100DaysOfCode #Python #Arrays #Programming #ProblemSolving #LearningToCode #CodingJourney #Day47
To view or add a comment, sign in
-
-
Today I worked on a Python logic exercise focused on list traversal, duplicate handling, and comparing two lists of different lengths using pure loops. 🔹 What this code does: Takes two lists with different lengths, both containing repeated numbers Iterates through them safely using index-based nested loops Collects common elements while preserving order Removes duplicate values manually, without using built-in shortcuts like set() 🔹 Why I approached it this way: Instead of relying on Python conveniences, I deliberately used: Explicit for loops Conditional logic Intermediate lists This forced me to think about: Boundary conditions when list sizes don’t match How duplicates are detected step by step Writing logic that doesn’t assume equal input sizes 🔹 Key takeaway: Understanding fundamentals—especially edge cases like unequal input lengths—builds stronger problem-solving skills than jumping straight to optimized one-liners. Consistent practice, steady improvement. 💻📈 #Python #Programming #LogicBuilding #DataStructures #ProblemSolving #CodingPractice
To view or add a comment, sign in
-
-
LeetCode Progress | 228. Summary Ranges (Python) Today I solved “Summary Ranges” on LeetCode. Problem: Given a sorted unique integer array nums, return the smallest list of ranges that cover all numbers exactly. A range should be formatted as: -- "a->b" if a != b -- "a" if a == b My approach: I used a two-pointer style tracking method. -- Set start as the beginning of a range -- Iterate through the array and detect when the sequence breaks -- When it breaks, append either a single number or a start->end range -- Update start to begin the next range Optimal approach: The optimal solution follows the same greedy idea (range tracking in one pass). -- Maintain start and extend the current range while consecutive numbers continue -- When the chain breaks or the array ends, output the range and reset start This provides an efficient solution with: -- Time Complexity: O(n) -- Space Complexity: O(1) (excluding output list) What I learned: -- Range problems become easy when you track only the start and detect breakpoints -- Always handle the last element carefully to avoid missing the final range -- Greedy one-pass scanning is often optimal for sorted arrays #leetcode #python #dsa #datastructures #algorithms #coding #programming #problemSolving #softwareengineering #computerscience #interviewprep #codinginterview #100daysofcode #pythonprogramming
To view or add a comment, sign in
-
-
🚀 Day 54 of #100DaysOfCode — Array Slicing & Efficiency Hey everyone! 👋 Today’s task was a fundamental one: Removing the first element of an array. While there are many ways to do this, today was about finding the most efficient and readable approach in Python. 👨💻 What I practiced today: ✅ Manual Iteration: Using for loops to reconstruct arrays. ✅ Array Slicing: Leveraging arr[1:] for cleaner, faster code. ✅ Performance Mindset: Understanding the trade-offs between manual loops and built-in methods. 📌 Today’s Task: ✔ Input: An array like [1, 2, 3] ✔ Goal: Remove the first element and return the rest. ✔ Expected Output: [2, 3] 🧠 Key Insight: In Python, we can skip the manual for loop and append() calls. Using Slicing (arr[1:]) is not only more readable but also more efficient because it’s implemented at the C-level in Python. 💡 The "Pythonic" Evolution: Manual (What I wrote): Loop from index 1 to end (O(n) time). Optimized: return arr[1:] — Simple, fast, and clean. ✨ Key Takeaway: Code readability is just as important as logic. Moving from a 4-line loop to a 1-line slice makes the intent of the code immediately clear to anyone reading it. #100DaysOfCode #Day54 #Python #CodingJourney #DSA #CleanCode #ArrayManipulation #ProgrammingTips #LearnToCode
To view or add a comment, sign in
-
-
Today was all about going deeper into Python fundamentals 🐍💡 📌 What I covered today: 🔹 Scope (LEGB Rule) Understood how Python searches for variables and why scope matters for clean and predictable code. 🔹 Closures Learned how inner functions can remember variables from their enclosing scope even after the outer function has finished execution — powerful concept for state management and decorators. 🔹 OOPS – Class & Object Explored why classes are used over only functions: - Classes act as blueprints - Objects are real instances - Better structure, data protection, scalability, and real-world modeling - Also clarified how __init__ works and how each object maintains its own state. 👉 Revisiting fundamentals really changes how you think about writing better, cleaner code. Learning step by step, one concept at a time 🚀 #Python #LearningInPublic #PythonBasics #OOPS #Closures #Scope #Programming #DeveloperJourney
To view or add a comment, sign in
-
🧠 𝟯𝗿𝗱-𝗦𝘁𝗲𝗽 𝗣𝘆𝘁𝗵𝗼𝗻 𝗠𝗮𝘀𝘁𝗲𝗿𝘆 𝗦𝗲𝗿𝗶𝗲𝘀: 𝗖𝗼𝗻𝘁𝗿𝗼𝗹 𝗙𝗹𝗼𝘄 𝗨𝗻𝗹𝗼𝗰𝗸𝗲𝗱! 𝗘𝘃𝗲𝗿 𝘄𝗼𝗻𝗱𝗲𝗿𝗲𝗱 𝗵𝗼𝘄 𝗽𝗿𝗼𝗴𝗿𝗮𝗺𝘀 𝘁𝗵𝗶𝗻𝗸 𝗮𝗻𝗱 𝗺𝗮𝗸𝗲 𝗱𝗲𝗰𝗶𝘀𝗶𝗼𝗻𝘀?That's the magic of Control Flow, and it's what separates basic scripts from truly dynamic and intelligent applications! In Part 3 of my 11-step Python Mastery Series, we're diving deep into the brain of your code. We’ll be unlocking the power to guide your program through different paths based on conditions. 𝗚𝗲𝘁 𝗿𝗲𝗮𝗱𝘆 𝘁𝗼 𝗺𝗮𝘀𝘁𝗲𝗿:- 🎯 𝗖𝗼𝗻𝗱𝗶𝘁𝗶𝗼𝗻𝗮𝗹 𝗦𝘁𝗮𝘁𝗲𝗺𝗲𝗻𝘁𝘀 (𝗶𝗳, 𝗲𝗹𝗶𝗳, 𝗲𝗹𝘀𝗲)𝘀𝘁𝗲𝗿:: Teaching your code to react smartly to various scenarios. ⚖️ 𝗟𝗼𝗴𝗶𝗰𝗮𝗹 𝗢𝗽𝗲𝗿𝗮𝘁𝗼𝗿𝘀 (𝗮𝗻𝗱, 𝗼𝗿, 𝗻𝗼𝘁): Combining conditions for complex decision-making. 🔄 𝗡𝗲𝘀𝘁𝗲𝗱 𝗖𝗼𝗻𝘁𝗿𝗼𝗹 𝗙𝗹𝗼𝘄: Building intricate logic structures for sophisticated applications. This isn't just about syntax; it's about fundamentally changing how you approach problem-solving with Python. Imagine your programs responding differently based on user input, data values, or even time of day! Why is Control Flow crucial? It's the engine that drives all complex applications, allowing them to adapt, respond, and perform tasks exactly when and how they should. Without it, your code is just a straight line. With it, you build pathways! Join me as we empower our Python programs to think, decide, and act. This is where your coding truly gets interesting! #Python #ControlFlow #ProgrammingLogic #PythonSeries #ConditionalStatements #CodingSkills #SoftwareDevelopment #LearnInPublic #TechEducation #MachineLearning #DataAnalysis #CodingJourney #SmartManufaturing #OperationAnalyst #IndustrialDataScientist
To view or add a comment, sign in
-
-
Problem: Print Elements of a Linked List Concepts: Linked List Traversal | Pointers | Iteration Difficulty: Easy Problem Summary: Given the head of a singly linked list, traverse the list and print the data of each node line by line. If the head is NULL, nothing should be printed. This problem focuses on understanding how to move through nodes using pointers and access data stored in each node. Key Learnings: A linked list is traversed using a temporary pointer that starts at the head Each node stores both data and a next pointer Traversal continues until the pointer becomes NULL Proper pointer movement is essential to avoid infinite loops GitHub Link:https://lnkd.in/dfxDCKdq #Day40 #DSA #LinkedList #ProblemSolving #DataStructures #Coding #Python #Cplusplus #LearningInPublic #50DaysChallenge #TechJourney
To view or add a comment, sign in
-
-
Late-night debugging teaches you one thing fast: tools matter 🕒🐍 I recently read a piece on Python libraries that quietly transform messy scripts into calm, production-ready automation — and it hit close to home. Key takeaway 👇 It’s not always about new frameworks or rewrites. Sometimes, the right library removes entire categories of bugs. 📌 Example: Using tools like pathlib means: ✅ No string-based path chaos ✅ Cleaner, readable file automation ✅ Fewer OS-specific surprises Small changes. Massive payoff. The kind that saves hours and your sanity. If you write Python regularly, this is a reminder worth revisiting. 🚀 #Python #Automation #CleanCode #DeveloperExperience #Productivity
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development