Jan-07-2019, 01:21 PM
Hello,
I'm trying to write a solution for exercise 12.4 from "Think Python", and I have a strange behavior of my return value.
Here's the code:
Where is the error? Thank you.
I'm trying to write a solution for exercise 12.4 from "Think Python", and I have a strange behavior of my return value.
Here's the code:
def tuple_list_dict_init(w_list): """ Return a dictionary that have as keys tuples of letters(sorted) from words in a given list. w_list: a given list of words. Should be of type list of strings. d = dict() """ for l in w_list: # this loop for test purposes only if (type(l) is int): print('Integer detected') for w in w_list: if (type(tuple(sorted(w))) is int): # this conditional for test purposes only print('Integer key detected') d.setdefault(tuple(sorted(w)), []) return dWhen I call this function no 'print' is executed. But in the returned dictionary I can find key of type 'int'.
Where is the error? Thank you.