13 lines
454 B
Python
13 lines
454 B
Python
def permute_string(str):
|
|
if len(str) == 0:
|
|
return ['']
|
|
prev_list = permute_string(str[1:len(str)])
|
|
next_list = []
|
|
for i in range(0,len(prev_list)):
|
|
for j in range(0,len(str)):
|
|
new_str = prev_list[i][0:j]+str[0]+prev_list[i][j:len(str)-1]
|
|
if new_str not in next_list:
|
|
next_list.append(new_str)
|
|
return next_list
|
|
|
|
print(permute_string('ABCD')); |