[Tutor] Sorting a List
Corey Richardson
kb1pkl at aim.com
Thu Jan 13 01:56:31 CET 2011
Hello Tutors,
I am generating XML definitions for animations to be used in a
FIFE-based game. I need to sort the frames of the animations, and I am
currently using:
sorted([image for image in os.listdir(path) if image.endswith('.png')])
The final output in the XML is:
<frame source="walk_0.png"/>
<frame source="walk_1.png"/>
<frame source="walk_10.png"/>
<frame source="walk_11.png"/>
<frame source="walk_2.png"/>
<frame source="walk_3.png"/>
<frame source="walk_4.png"/>
<frame source="walk_5.png"/>
<frame source="walk_6.png"/>
<frame source="walk_7.png"/>
<frame source="walk_8.png"/>
<frame source="walk_9.png"/>
Having frame 10 and 11 between frame 1 and 2 is not desired behavior;
how can I sort all of these with walk_10.png and company (this isn't the
only animation like this) being after walk_9.png? A google search
doesn't return anything I could use. I tried just using
[image for image in os.listdir(path) if image.endswith('.png')],
but that doesn't appear to have any order.
Thanks,
Corey Richardson
More information about the Tutor
mailing list