From 63c8402b2bddc23f8d1aa5e17552e01516dcbc08 Mon Sep 17 00:00:00 2001 From: Vedant Nukte <116732251+NukeVdnt@users.noreply.github.com> Date: Sat, 4 Jan 2025 00:20:47 +0530 Subject: [PATCH] Update Group Anagrams - Leetcode 49.py Instead of directly returning dict.values iterable, we change it to list to avoid the return type error --- Group Anagrams - Leetcode 49/Group Anagrams - Leetcode 49.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Group Anagrams - Leetcode 49/Group Anagrams - Leetcode 49.py b/Group Anagrams - Leetcode 49/Group Anagrams - Leetcode 49.py index 06af914..e6d51a5 100644 --- a/Group Anagrams - Leetcode 49/Group Anagrams - Leetcode 49.py +++ b/Group Anagrams - Leetcode 49/Group Anagrams - Leetcode 49.py @@ -22,8 +22,9 @@ def groupAnagrams(self, strs: List[str]) -> List[List[str]]: count[ord(c) - ord("a")] += 1 key = tuple(count) anagrams_dict[key].append(s) - - return anagrams_dict.values() + # we need to convert the dict.values iterable to list, otherwise we get the following error + # error : "dict_values([['eat', 'tea', 'ate'], ['tan', 'nat'], ['bat']]) is not valid value for the expected return type list>" + return list(anagrams_dict.values()) # n is the number of strings, m is the length of largest string # Time Complexity: O(n * m) # Space Complexity: O(n * m)