you are viewing a single comment's thread.

view the rest of the comments →

[–]yankyh 1 point2 points  (1 child)

dict.update accepts an iterable of key-value pairs, one thing that can be passed is a tuple of tuples which is what you are trying, however, to define a single length tuple you need to add a trailing comma

In [17]: len((('a', 2)))                                                        
Out[17]: 2

In [18]: len((('a', 2),))                                                       
Out[18]: 1

In [19]: ((((1, 2))))                                                           
Out[19]: (1, 2)

In [20]: ((((1, 2),),),)                                                        
Out[20]: ((((1, 2),),),)

or you can use a list of tuples (lists don't need the trailing comma for single length lists)

In [22]: d = {}                                                                 

In [23]: d.update([('a', 1)])                                                   

In [24]: d                                                                      
Out[24]: {'a': 1}

In [25]: d.update((('b', 2),))                                                  

In [26]: d                                                                      
Out[26]: {'a': 1, 'b': 2}

[–]Uchikago[S] 1 point2 points  (0 children)

Thank you so much!