tags:

views:

32

answers:

2

I need to sort string, and I came up with the following function.

def mysort(comb_): 
    str = [] 
    size = len(comb_) 
    for c in comb_: 
        str.append(c) 
    str.sort() 
    return ''.join(str) 

Is there any way to make it compact?

+5  A: 
return ''.join(sorted(comb_))
Ignacio Vazquez-Abrams
This is the correct answer. It cannot get more succinct (or idiomatic) than that. Disregarding the strange underscore in the variable name, of course.
jemfinch
A: 
def sortstr(comb_):
    return ''.join(sorted(comb_))

e:f;b :(

Jason Hall