- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Program to find length of a list without using built-in length() function in Python

Suppose we have a list nums. We have to find the length of this list but without using any length(), size() or len() type of functions.

So, if the input is like nums = [5,7,6,4,6,9,3,6,2], then the output will be 9.

To solve this, we will follow these steps −

- Solve this by map and list operations
- x := a list which contains all elements in nums
- convert all elements in x to 1
- find sum of x by using sum() method
- In this example we have used the map() method to convert all into 1 by defining an anonymous function.

## Example

Let us see the following implementation to get better understanding −

def solve(nums): return sum(map(lambda x:1, nums)) nums = [5,7,6,4,6,9,3,6,2] print(solve(nums))

## Input

[5,7,6,4,6,9,3,6,2]

## Output

9

- Related Questions & Answers
- Python Program to Find the Length of the Linked List without using Recursion
- Python Program to Find the Length of a List Using Recursion
- Python Program to Calculate the Length of a String Without Using a Library Function
- Program to find length of longest matrix path length in Python
- Python Program to Find the Length of the Linked List using Recursion
- Java string length without using length() method.
- Program to find minimum length of lossy Run-Length Encoding in Python
- Program to find maximum length of k ribbons of same length in Python
- Program to find length of longest interval from a list of intervals in Python
- Program to find length of longest arithmetic subsequence of a given list in Python
- Program to find Length of Bridge using Speed and Length of Train in C++
- Length of a Linked List in Python
- C program to find the length of linked list
- Program to find length of the longest path in a DAG without repeated nodes in Python
- Program to find length of longest Fibonacci subsequence from a given list in Python

Advertisements