Two newbie questions

Manus Hand mjhand at concentric.net
Tue Jun 13 14:57:40 EDT 2000


To sort the characters in a string:

import string
aList = list(yourString)
aList.sort()
yourString = string.join(aList, '')

To get a random number between -sys.maxint and sys.maxint:

import random
yourNumber = random.randrange(sys.maxint) * [1,-1][random.randrange(2)]

[Note that random.randrange(-sys.maxint, sys.maxint) should work but instead
functions as a request for an OverflowError.]

Hope this helps,
Manus





More information about the Python-list mailing list