python array | Sort the array in descending order. Email ThisBlogThis!Share to TwitterShare to Facebook Reactions: Python 5 Comments
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeletedef sor(a,t):
ReplyDeleteprint a
for i in range(1,t):
for j in range(0,t-i):
if a[j]<a[j+1]:
temp=a[j]
a[j]=a[j+1]
a[j+1]=temp
print a
mylist=[43,5,4,23,4,45,5,655]
s=len(mylist)
sor(mylist,s)
[43, 5, 4, 23, 4, 45, 5, 655]
[655, 45, 43, 23, 5, 5, 4, 4]
mylist=[1,2,3,4,5,6]
ReplyDeletemylist.sort(reverse=True)
print mylist
mylist=[2,4,6,8,10]
ReplyDeletemylist sort(reverse=true)
print "mylist"
[2,4,6,8,10]
[10,8,6,4,2]