- 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
- Python Advanced Tutorial
- Python - Classes/Objects
- Python - Reg Expressions
- Python - CGI Programming
- Python - Database Access
- Python - Networking
- Python - Sending Email
- Python - Multithreading
- Python - XML Processing
- Python - GUI Programming
- Python - Further Extensions
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.
- Related Articles
- 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?
- Why you should use NumPy arrays instead of nested Python lists?
- Nested media lists with Bootstrap
- How to index and slice lists in Python?
- 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 access elements of nested lists in R?
- Minimum Index Sum of Two Lists in C++
- Python program to print all the common elements of two lists.
- Python program to find Intersection of two lists?
- Python to Find number of lists in a tuple
- Find common elements in list of lists in Python
- Python program to find Cartesian product of two lists
- Program to find a list of product of all elements except the current index in Python