anagrams

Run Settings
LanguagePython
Language Version
Run Command
data = ['eat', 'ate', 'tea', 'ant', 'tan', 'bat', 'adobe', 'abode', 'listen', 'silent'] def createAnagramKey(string): key = '' for ch in sorted(string): key += ch return str(key) def groupAnagramWords(data): group = dict() for ele in data: if group.get(createAnagramKey(ele)) == None: group[createAnagramKey(ele)] = [ele] else: group[createAnagramKey(ele)].append(ele) return group anagram_grouped = groupAnagramWords(data) # Anagram in dictonry format print('In dictonry format') print(anagram_grouped) anagram_grouped_list = list() print("d") for k, v in anagram_grouped.items(): anagram_grouped_list.append(v) print('In list format') print(anagram_grouped_list)
Editor Settings
Theme
Key bindings
Full width
Lines