some_list = ['bad', 'app', 'sad', 'mad', 'dab','pge', 'bda', 'ppa', 'das', 'dba']
new_list = []
from collections import OrderedDict
for ele in OrderedDict.fromkeys("".join(sorted(ele)) for ele in some_list):
temp = []
for s in some_list:
if ele == ''.join(sorted(s)):
temp.append(s)
if len(temp) > 1:
new_list.append(temp)
for i in new_list:
i.sort()
print(i)
The output is:
['bad', 'bda', 'dab', 'dba']
['app', 'ppa']
['das', 'sad']
I want the output to be:
['app', 'ppa']
['bad', 'bda', 'dab', 'dba']
['das', 'sad']
How do I change the code to get the right output?