- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find size of a list in Python
A list is a collection data type in Python. The elements in a list are change able and there is no specific order associated with the elements. In this article we will see how to find the length of a list in Python. Which means we have to get the count of number of elements present in the list irrespective of whether they are duplicate or not.
In the below example we take a list named as "days". We first find the length of the list using len() function. And then we add few more elements and check the length again using append() function. Finally we remove some elements using remove() function and check the length again. Please note even though the elements are duplicate the remove() function will remove only e the elements at the end of the list
days = ["Mon","Tue","Wed"] print (len(days)) # Append some list elements days.append("Sun") days.append("Mon") print("Now the list is: ",days) print("Length after adding more elements: ",len(days)) # Remove some elements days.remove("Mon") print("Now the list is: ",days) print("Length after removing elements: ",len(days))
Running the above code gives us the following result −
3 Now the list is: ['Mon', 'Tue', 'Wed', 'Sun', 'Mon'] Length after adding more elements: 5 Now the list is: ['Tue', 'Wed', 'Sun', 'Mon'] Length after removing elements: 4
- How to find the size of a list in C#?
- How do I find the size of a Java list?
- How to get the size of a list in Python?
- How do we get size of a list in Python?
- Break a list into chunks of size N in Python
- Find average of a list in python?
- How do we get the size of a list in Python?
- Python program to Find the size of a Tuple
- Program to find size of Doubly Linked List in C++
- What is the maximum size of list in Python?
- Program to find size of sublist where product of minimum of A and size of A is maximized in Python
- Program to find a sub-list of size at least 2 whose sum is multiple of k in Python
- Find Mean of a List of Numpy Array in Python
- Find elements of a list by indices in Python
- Program to find size of each partition of a list where each letter appears at most one piece in Python