

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Index specific cyclic iteration in list
In this tutorial, we are going to write a program that cyclically iterates a list from the given Let's see the steps to solve the problem
- Initialize the list and index.
- Find the length of the list using len.
- Iterate over the list using the length.
- Find the index of the element using index % length.
- Print the element.
- Increment the index.
It's a simple loop iteration. You can write it without any trouble. Let's see the code.
Example
# initializing the list and index alphabets = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] start_index = 5 # finding the length length = len(alphabets) # iterating over the list for i in range(length): # finding the index of the current element element_index = start_index % length # printing the element print(alphabets[element_index], end=' ') # incrementing the index for the next element start_index += 1
Output
If you run the above code, then you will get the following result.
f g h a b c d e
Conclusion
If you have any queries regarding the tutorial, mention them in the comment section.
- Related Questions & Answers
- Backward iteration in Python
- C++ Program to Find Chromatic Index of Cyclic Graphs
- Backward iteration in Python program
- Python – Check if elements in a specific index are equal for list elements
- Python Program to Cyclic Redundancy Check
- Python - Return index with a specific level removed
- Remove Substrings in One Iteration in python
- Equate two list index elements in Python
- Python – Index Value repetition in List
- How do I insert elements at a specific index in Java list?
- How to remove index list from another list in python?
- Program to check there is any forward path in circular cyclic list or not in Python
- Accessing index and value in a Python list
- Python – Negative index of Element in List
- Python – Append List every Nth index
Advertisements