words = ['eat', 'tea', 'tan', 'ate', 'nat', 'bat']
groups = []
for word in words:
key = ''.join(sorted(word))
found = False
for group in groups:
if group[0] == key:
group[1].append(word)
found = True
break
if not found:
groups.append([key, [word]])
for group in groups:
group[1].sort()
groups.sort()
result = []
for group in groups:
result.append(group[1])
print(result)