- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions

# 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 Articles
- Python Program to Find the Length of the Linked List without using Recursion
- Python Program to Calculate the Length of a String Without Using a Library Function
- Python Program to Find the Length of a List Using Recursion
- Python Program to Find the Length of the Linked List using Recursion
- Program to find length of longest arithmetic subsequence of a given list in Python
- Program to find length of longest interval from a list of intervals in Python
- Program to find length of longest matrix path length in Python
- Program to find length of the longest path in a DAG without repeated nodes in Python
- Program to find length of longest alternating subsequence from a given list in Python
- Program to find length of longest Fibonacci subsequence from a given list in Python
- 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
- Find maximum length sub-list in a nested list in Python
- Program to find length of longest sign alternating subsequence from a list of numbers in Python
- Length of a Linked List in Python

Advertisements