python OrderedDict update a list of keys with the same value -
i trying update list of keys ordereddict same int value, like
for idx in indexes: res_dict[idx] = value where value int variable, indexes list of ints, act keys, res_dict ordereddict, tried resolve above in 1 line,
res_dict[indexes]=value but got error:
typeerror: unhashable type: 'list' is loop or list comprehension way(s) update here?
the ordereddict (and dict well) provide method update update multiple values @ once.
the pythonic manner want :
res_dict.update((idx, value) idx in indexes) it keep original order of ordereddict.
Comments
Post a Comment