"prasad rao" <[email protected]> wrote in message news:[email protected]...
hello I am trying to sort a list(I know there is a builtin sort method).a=[21,56,35,47,94,12] b=[] for x in a: b.append (min(a)) a.remove (min(a)) >>> a [56, 47, 94] >>> b [12, 21, 35] It is not Compleating .Doing only 3 rounds.Why?
You should not change a list while iterating over it. Instead, iterate until a is empty:
a=[21,56,35,47,94,12] b=[] while a:
... b.append(min(a)) ... a.remove(min(a)) ...
a
[]
b
[12, 21, 35, 47, 56, 94]
-Mark _______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
