FAQ  •  Login

sorting of a list

Moderators: UncleTimmy, mjpieters

Enjoying the challenge? Need a hint?
Make a donation and help keep the site running! -thesamet
<<

sumit kumar

Posts: 4

Joined: Tue Jan 10, 2012 12:44 am

Post Tue Jan 10, 2012 12:57 am

sorting of a list

def sort():
a=[2,5,4,9,11,7]

print("list before sorting is:")
print(a)
for i in a:
for j in range(i+1,len(a)):

if a[i]<a[j]:

temp=a[i]+a[j]
a[i]=temp-a[i]
a[j]=temp-a[j]
print ("list after sorting is:")
print a
how can we write a sorted array list.is this code is correct.please send me a correct code
<<

blast_hardcheese

Posts: 32

Joined: Wed Aug 17, 2011 12:52 am

Post Tue Jan 10, 2012 1:24 am

Re: sorting of a list

  Code:
def sort():
    a=[2,5,4,9,11,7]

    print("list before sorting is:")
    print(a)

    a.sort()

    print("list after sorting is:")
    print(a)


?

If you're looking for how to sort yourself, take a look at the theory here:
http://en.wikipedia.org/wiki/Bubble_sort
http://en.wikipedia.org/wiki/Cocktail_sort
http://en.wikipedia.org/wiki/Odd–even_sort
http://en.wikipedia.org/wiki/Comb_sort
http://en.wikipedia.org/wiki/Gnome_sort
http://en.wikipedia.org/wiki/Quicksort
http://en.wikipedia.org/wiki/Stooge_sort
http://en.wikipedia.org/wiki/Bogosort
<<

sumit kumar

Posts: 4

Joined: Tue Jan 10, 2012 12:44 am

Post Tue Jan 10, 2012 2:54 am

Re: sorting of a list

thanku u

Return to Suggestions

Who is online

Users browsing this forum: Google [Bot] and 6 guests

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.