[Tutor] sort problem
Roelof Wobben
rwobben at hotmail.com
Wed Sep 8 17:22:44 CEST 2010
Hello,
I have this :
def sort_sequence(seq):
"""
>>> sort_sequence([3, 4, 6, 7, 8, 2])
[2, 3, 4, 6, 7, 8]
>>> sort_sequence((3, 4, 6, 7, 8, 2))
(2, 3, 4, 6, 7, 8)
>>> sort_sequence("nothappy")
'ahnoppty'
"""
if type(seq) == type([]):
seq.sort()
elif type(seq)== type(()):
seq = tuple(sorted(seq))
else:
seq2 = list(seq)
seq2.sort()
print seq2
seq.join(seq2)
return seq
The problem is that if I want to sort the characters in a string, the list exist of the sorted characters but as soon as I convert them to a string I get the old string.
What went wrong ?
Roelof
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100908/99fdb9ba/attachment.html>
More information about the Tutor
mailing list