Hi!! :)
Can someone help
me to write a code that with sort through a list of strings which are peoples names
without using the python sort function.

So the rules are :

We start with an initial pile containing only the first name in the list.

Go through all the other names in the list from left to right and place each name on top of the left most
pile for which it is less than the name on top of this pile. If there is no such pile, we create a new pile
containing this name to the right of the other piles.

Until all the piles are empty, we repeatedly select and remove the smallest name among all those on top
of the pile.

The code I have so far is :

def psort(L):

M = [L[0]]

for i in L[1:]:

J = [M[0]]

print J

if J > i:

M = M +[i]


create a new pile

M = [i] + M

print M

I was wondering how would I create new lists , since I do not know in the beginning how many piles/lists
will be needed.

Thanks ;) Rouby + Mona
Ps= CS is killing us any help would be appreciated :'(

4 Years
Discussion Span
Last Post by pyTony
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.