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]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python | Custom list split
- Python | Custom Multiplication in list of lists
- Python | Custom slicing in List
- Python | Custom sorting in list of tuples
- Python - Initialize dictionary with custom value list
- Python - Custom dictionary initialization in list
- Python | Custom List slicing Sum
- Python - Sublist Maximum in custom sliced List
- Python - Add Custom Column to Tuple list
- Python - Values from custom List in Records
- Python - Add custom values key in List of dictionaries
- Python - Sort list of Single Item dictionaries according to custom ordering
- Python - Custom Lower bound a List
- Python | Join cycle in list
- Python | User groups with Custom permissions in Django
- Python | Custom length Matrix
- Python | Custom Index Range Summation
- Python | Consecutive Custom Chunked elements Product
- Python - Matrix Custom Multiplier
- Python - Custom Rows Removal depending on Kth Column
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.