Can Anyone Help me on this

Mike Meyer mwm at mired.org
Thu Nov 3 14:16:01 EST 2005


jmdeschamps at gmail.com writes:
> If what you want is a reversed copy, you could just append list1
> elements to list2, and use the reverse function such as
>>>> ...
>>>> for i in list1:
> ... 	list2.append(i)
> ...

Don't do this by ahnd - let python do it for you:

list2 = list(list1)

or

list2 = list1[:]

      <mike

>>>> list2.reverse()
>>>> list1
> ['1', '2', '3', '4', '5', '6', '7', '8', '9']
>>>> list2
> ['9', '8', '7', '6', '5', '4', '3', '2', '1']
>

-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list