Python Tutorial

Thursday, June 7, 2012

python sorted: sort array

I like sorted because it is easy to use, sort multi structered data and also keep the original data which very important some times
 
a=[3,2,1,4,5]
print a
print sorted(a)
print sorted(a,reverse=True)
print a


Output:
[3, 2, 1, 4, 5]
[1, 2, 3, 4, 5]
[5, 4, 3, 2, 1]
[3, 2, 1, 4, 5]

0 comments:

Post a Comment