[Tutor] List Changing Order
Steven D'Aprano
steve at pearwood.info
Fri Nov 26 07:25:26 CET 2010
Corey Richardson wrote:
> Tutors,
>
> I recall that the keys of dictionaries have arbitrary order, and may
> change over time. Is this true of lists? I can't find the answer from a
> simple Google search. Thank you!
Only if you re-arrange it yourself.
list.sort(), list.reverse() and random.shuffle(list) explicitly change
the list's order. You can also manually move items around, e.g.:
list[3], list[5] = list[5], list[3] # swap items 3 and 5
but otherwise lists keep their order.
--
Steven
More information about the Tutor
mailing list