The splitting of lists is quite common utility nowadays and there can be many applications and use cases of the same. Along with these always come the variations. One such variation can be split the list by particular value. Let’s discuss a certain way in which list split can be performed.
Method : Using list comprehension +
zip() + slicing + enumerate()
This problem can be solved in two parts, in first part we get the index list by which split has to be performed using enumerate function. And then we can join the values according to the indices using zip and list slicing.
The original list : [1, 4, 5, 6, 4, 5, 6, 5, 4] The list after splitting by a value : [[1, 4, 5], [6, 4, 5], [6, 5], ]
- Python | Split nested list into two lists
- Python | Split dictionary of lists to list of dictionaries
- Python | Pandas Split strings into two List/Columns using str.split()
- Python | Split the Even and Odd elements into two different lists
- Python | Split dictionary keys and values into separate lists
- Python | Program to count number of lists in a list of lists
- Python | Custom list split
- Python | Sorting list of lists with similar list elements
- Python | Merge List with common elements in a List of Lists
- Python | Split a list into sublists of given lengths
- Python | Split list in uneven groups
- Python | Split string into list of characters
- Python | Split a list having single integer
- Python | Maximum sum of elements of list in a list of lists
- Python | Check if a list exists in given list of lists
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.