Group Anagrams
Problem to find the different group of anagrams. Each group must be ascending order.All combined group must be ascending order.
Example-1:
Input : n = [ "eat", "tea", "tan", "ate", "nat", "bat"] Output : [['ate', 'eat', 'tea'], ['bat'], ['nat', 'tan']]
Example-2:
Input : n = [ "cat", "tac", "act", "part", "trap"] Output : [['act', 'cat', 'tac'], ['part', 'trap']]
Solution
n = [ "eat", "tea", "tan", "ate", "nat", "bat"] k = [] z = [] for x in n: l = [] for y in range(len(n)): if(sorted(x) == sorted(n[y])): l.append(n[y]) l = sorted(l) if(l not in k): k.append(l) print(sorted(k))
Output
[['ate', 'eat', 'tea'], ['bat'], ['nat', 'tan']]