[Tutor] List Changing Order
Corey Richardson
kb1pkl at aim.com
Fri Nov 26 15:20:44 CET 2010
Steven D'Aprano wrote:
> 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.
>
Many thanks, everyone who replied.
More information about the Tutor
mailing list