[Tutor] Rearranging a list

Ken G. beachkidken at gmail.com
Thu Feb 26 13:13:57 CET 2015


Assuming I have the following list and code how do I best be able 
rearrange the list as stated below:

list = [0, 0, 21, 35, 19, 42]

Using print list[2:6] resulted in the following:

2    21
3    35
4    19
5    42

I would like to rearrange the list as follow:

5    42
3    35
2    21
4    19

I tried using list.reverse() and print list[0,6] and it resulted in:

[42, 19, 35, 21, 0, 0] or as printed:

0    42
1    19
2    35
3    21
4    0
5    0

In another words, I would desire to show that:

5 appears 42 times
3 appears 35 times
2 appears 21 times
4 appears 19 times

but then I lose my original index of the numbers by reversing. How do I 
best keep the original index number to the rearrange numbers within a list?

Thanking in advance,

Ken






More information about the Tutor mailing list