Reverse list

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
Thundy
Regular
Posts: 88
Joined: Tue Dec 05, 2017 9:08 am
Contact:

Reverse list

#1 Post by Thundy »

He all is there a way to loop through a list in reverse?

for i,q in enumerate(list): would go through it from 0 to X but i want to cyce through from X to 0 instead.

Thundy
Regular
Posts: 88
Joined: Tue Dec 05, 2017 9:08 am
Contact:

Re: Reverse list

#2 Post by Thundy »

or alternatively a way to add new items to the start of a list rather than the end would serve equally as well :)

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2402
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Reverse list

#3 Post by Ocelot »

is there a way to loop through a list in reverse?
https://docs.python.org/2/library/funct ... l#reversed

Code: Select all

for i,j in reversed(enumerate(some_list)):

# Or, depending on what you want:
for i,j in enumerate(reversed(some_list)):
or alternatively a way to add new items to the start of a list

Code: Select all

foo = 9000
some_list.insert(0, foo)
# Or
some_list = [ foo ] + some_list
< < insert Rick Cook quote here > >

Thundy
Regular
Posts: 88
Joined: Tue Dec 05, 2017 9:08 am
Contact:

Re: Reverse list

#4 Post by Thundy »

Awesome thanks Ocelot. that will do nicely :D

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], fufuffiero