Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorting elements in string with Python

Tags:

python

sorting

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?

like image 249
prosseek Avatar asked Apr 08 '10 02:04

prosseek


1 Answers

return ''.join(sorted(comb_))
like image 119
Ignacio Vazquez-Abrams Avatar answered Oct 14 '22 06:10

Ignacio Vazquez-Abrams