49. Group Anagrams
Medium
Problem:
Input: strs = ["eat","tea","tan","ate","nat","bat"]
Output: [["bat"],["nat","tan"],["ate","eat","tea"]]What to learn:
sorted()
strs = ["eat", "tea", "tan", "ate", "nat", "bat"]
for word in strs:
print(sorted(word))c = ['ccc', 'aaaa', 'd', 'bb']
sorted(c, key=len)
a = ['cde', 'cfc', 'abc']
sorted(a, key=lambda s: (s[0], s[-1])) # sort by the first character, and then the last onesort()
Solutions:
Another approach
Last updated