Implementing Custom len() Function in Python

Day 33 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to implement a custom version of the len() function. Instead of using Python’s built-in len() function, I created my own function to count the number of elements in an iterable. What the program does: • Takes any iterable as input (list, string, tuple, etc.) • Iterates through each element • Counts elements one by one • Returns the total length How the logic works: 1)A function manual_len(iterable) is defined 2)A variable count is initialized to 0 3)The program loops through each element in the iterable 4)For every element, the counter is incremented by 1 5)After the loop ends, the final count is returned Example: List:[1, 2, 3, 4, 5] Output: Length = 5 String: "Hello, Colab!" Output: Length = 13 Tuple: (10, 20, 30) Output: Length = 3 Why this is useful: – Helps understand how built-in functions work internally – Demonstrates iteration over different data types – Strengthens understanding of iterables in Python Key learnings from Day 33: – Implementing built-in functionality manually – Working with iterables in Python – Understanding loops and counters – Strengthening Python fundamentals #100DaysOfCode #Day33 #Python #PythonProgramming #Algorithms #ProblemSolving #CodingPractice #LearnByDoing #ProgrammingJourney #DeveloperGrowth #ComputerScience #InterviewPrep #BTech #CSE #AIandML #VITBhopal #TechJourney

  • text

To view or add a comment, sign in

Explore content categories