Appending to a list, which is value of a dictionary

Wolfgang Maier wolfgang.maier at biologie.uni-freiburg.de
Sat Oct 15 12:51:22 EDT 2016


On 15.10.2016 18:16, Steve D'Aprano wrote:
> # Python 3 only: use a dict comprehension
> py> d = {x:[] for x in (1, 2, 3)}
> py> d
> {1: [], 2: [], 3: []}

dict (and set) comprehensions got backported so this works just as well 
in Python 2.7

Wolfgang




More information about the Python-list mailing list