[Tutor] How to create a dictionary for ount elements

Wolfgang Maier wolfgang.maier at biologie.uni-freiburg.de
Tue Jun 3 23:53:09 CEST 2014


On 03.06.2014 21:56, Wolfgang Maier wrote:

> - the tricky part is what to do with keys that are encountered for the
> first time and, thus, don't have a set associated with them yet.
> Here, dict.setdefault() will help you
> (https://docs.python.org/2.7/library/stdtypes.html?highlight=setdefault#dict.setdefault).
>
> hint: your_dict(your_key, set()).add(the_gene) will work whether or not
> the key has been encountered before or not.

I meant:

your_dict.setdefault(your_key, set()).add(the_gene)




More information about the Tutor mailing list