- 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 - Convert List to custom overlapping nested list
When it is required to convert a list to a customized overlapping nested list, an iteration along with the ‘append’ method can be used.
Below is a demonstration of the same
my_list = [31, 25, 36, 76, 73, 89, 91, 100] print("The list is :") print(my_list) my_step, my_size = 3, 4 my_result =  for index in range(0, len(my_list), my_step): my_result.append(my_list[index: index + my_size]) print("The result is :") print(my_result)
The list is : [31, 25, 36, 76, 73, 89, 91, 100] The result is : [[31, 25, 36, 76], [76, 73, 89, 91], [91, 100]]
A list is defined and is displayed on the console.
Two integers are defined.
An empty list is defined.
The original list is iterated over, and the element at a specific index is appended to the empty list.
This list is the result which is displayed as output on the console.
- Python - Convert given list into nested list
- Convert a nested list into a flat list in Python
- Python program to Flatten Nested List to Tuple List
- Python - Convert list of nested dictionary into Pandas Dataframe
- Convert Nested Tuple to Custom Key Dictionary in Python
- Nested list comprehension in python
- Custom list split in Python
- Python - Convert list of string to list of list
- Convert list of string to list of list in Python
- Convert list of tuples to list of list in Python
- Python How to copy a nested list
- Convert string enclosed list to list in Python
- Flatten Nested List Iterator in Python
- Python - Convert List of lists to List of Sets
- Nested List Weight Sum II in Python