Is there an easy way to sort the letters in a string alphabetically in Python?
a = 'ZENOVW'
I would like to return:
You can do:
>>> a = 'ZENOVW' >>> ''.join(sorted(a)) 'ENOVWZ'
>>> a = 'ZENOVW' >>> b = sorted(a) >>> print b ['E', 'N', 'O', 'V', 'W', 'Z']
sorted returns a list, so you can make it a string again using
>>> c = ''.join(b)
which joins the items of
b together with an empty string
'' in between each item.
>>> print c 'ENOVWZ'