Q12Multiple correct4 Marks1 Sep 2024
Consider the following python code. Each input is a word in which all the characters are in lower case. These will be set as argument when the function `word_shuffle()` is called. Select all set of arguments which will return `True`.
Hint: `dict.get(key, default_value)` returns the value corresponding to the `key`, if `key` is not found then it returns the `default_value`.
Example:
sample_dict = {'a' : 1}
sample_dict.get('a') # returns 1
sample_dict.get('b') # returns None
sample_dict.get('b', 0) # returns 0
Code Snippet
```
def word_shuffle(s, t):
if len(s) != len(t):
return False
dict_s = {}
dict_t = {}
for char in s:
dict_s[char] = dict_s.get(char, 0) + 1
for char in t:
dict_t[char] = dict_t.get(char, 0) + 1
return dict_s == dict_t
```