Your attempt:
d.update((k, v.upper()) for k,v in d.items())
This does not work. For example, v is list , you cannot upper list ...
This kind of conversion is best done using dictionary understanding to rebuild the new version of d . You can do the top for each value using a list comprehension:
d = {k:[v.upper() for v in vl] for k,vl in d.items()}
For your second question: starting from 1==True , set only stores the first inserted, which is 1 here. but can be True : example:
>>> {True,1} {1} >>> {True,1,True} {True} >>> {1,True} {True} >>>
more deterministic: pass a list to build a set instead of the notation set :
>>> set([True,1]) {True} >>> set([1,True]) {1}
Jean-François Fabre 01 Sep '17 at 15:52 2017-09-01 15:52
source share