Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I have a list of 1000 elements. How do I access all of them starting from last element to the first one in a loop.
list = [4,3,2,1] for item in list: print(from last to first)
output = [1,2,3,4]
for i in list_[::-1]:
Try:
list = [4,3,2,1] print [x for x in list[::-1]]
Output:
[1, 2, 3, 4]
Add a comment
list = [4,3,2,1] print [i for i in list[::-1]]
Which gives the desired [1, 2, 3, 4]
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
for i in list_[::-1]: