Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions strings/group_anagram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def group_anagrams(strs:list[str]) -> list[list[str]]:
""" Group word that are anagrams.
Two words are anagram if they contain the same
character in a different order.
:param words: List of input strings
:return :List of grouped anagrams
"""
res={}
for word in strs:
key="".join(sorted(word)) #fixed key
if key not in res:
res[key]=[]
res(key.append(word)) #fixed syntax
return list(res.values()) #fixed function call
if __name__ == "__main__"
print(group_anagrams["eat","tea","tan","ate","nat","bat"])

Check failure on line 16 in strings/group_anagram.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (invalid-syntax)

strings/group_anagram.py:16:1: invalid-syntax: Expected an indented block after `if` statement

Check failure on line 16 in strings/group_anagram.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (invalid-syntax)

strings/group_anagram.py:15:26: invalid-syntax: Expected `:`, found newline

Check failure on line 16 in strings/group_anagram.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (invalid-syntax)

strings/group_anagram.py:16:1: invalid-syntax: Expected an indented block after `if` statement

Check failure on line 16 in strings/group_anagram.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (invalid-syntax)

strings/group_anagram.py:15:26: invalid-syntax: Expected `:`, found newline
Loading