While working with Python lists, we can have a problem in which we need to perform the cycle of lists. This problem looks quite straight forward and has been discussed earlier. But sometimes, we need to perform it’s variations, hence making task challenging. We can have customizations such as elements from which cycling starts and Number of elements in cycle list. Let’s discuss solution to these variation.
Method : Using
dropwhile() + cycle() + islice()
This task can be performed using combination of above functions. In this, the elements are dropped till K with
dropwhile(), then the cycle can be done using
islice() is used to restrict the count of elements in list.
The original list is : [3, 4, 5, 7, 1] The cycled list is : [7, 1, 3, 4, 5, 7, 1, 3, 4, 5, 7, 1]
- Python | Custom slicing in List
- Python | Custom list split
- Python | Custom Multiplication in list of lists
- Python | Custom sorting in list of tuples
- Python | Join cycle in list
- Python | Custom length Matrix
- Python | User groups with Custom permissions in Django
- Python | Convert list of tuples to list of list
- Python | Convert list of string to list of list
- Python | Convert mixed data types tuple list to string list
- Python program to create a list of tuples from given list having number and its cube in each tuple
- Python | Convert list of numerical string to list of Integers
- Python | Convert string List to Nested Character List
- Python | Add list elements with a multi-list based on index
- Python | Merge list of tuple into list by joining the strings
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.