swapping numeric items in a list

faulkner faulkner612 at comcast.net
Tue Aug 22 20:39:23 EDT 2006


for i in xrange(0, len(your_list), 2):
    your_list[i], your_list[i + 1] = your_list[i + 1], your_list[i]


Jiang Nutao wrote:
> Hi,
>
> I simplify my problem like below
>
> To convert list
>     aa = [0x12, 0x34, 0x56, 0x78]
> into
>     [0x34, 0x12, 0x78, 0x56]
> 
> How to do it fast? My real list is huge.
> 
> Thanks a lot.
> Jason




More information about the Python-list mailing list