- 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
Python - Find starting index of all Nested Lists
When it is required to find the starting index of all nested lists, a simple iteration along with the ‘append’ method is used.
Below is a demonstration of the same
my_list = [, [91, 22, 36, 44], [25, 25], [46, 67, 78,82, 69, 29], [ 7, 5]] print("The list is :") print(my_list) my_result =  my_len = 0 for sub in my_list: my_result.append(my_len) my_len += len(sub) print("The initial element indices are :") print(my_result)
The list is : [, [91, 22, 36, 44], [25, 25], [46, 67, 78, 82, 69, 29], [7, 5]] The initial element indices are : [0, 1, 5, 7, 13]
A list of list is defined and is displayed on the console.
An empty list is defined, and an integer is assigned to 0.
The list is iterated over, and the integer is appended to the empty list.
The integer is incremented based on element in the list.
This empty list which is now populated is the result.
It is displayed as output on the console.
- Find minimum of each index in list of lists in Python
- Program to find starting index of the child who receives last balloon in Python?
- Nested media lists with Bootstrap
- All possible permutations of N lists in Python
- Program to find cost to reach final index of any of given two lists in Python
- How to index and slice lists in Python?
- How to access elements of nested lists in R?
- Python program to find Intersection of two lists?
- Minimum Index Sum of Two Lists in C++
- Find common elements in list of lists in Python
- Python to Find number of lists in a tuple
- Python program to find Cartesian product of two lists
- Python program to print all the common elements of two lists.
- Program to find a list of product of all elements except the current index in Python
- Python program to find Union of two or more Lists?