[Tutor] Dictionary viceversa
zachary.ware+pytut at gmail.com
Mon Jul 30 13:28:05 EDT 2018
On Mon, Jul 30, 2018 at 12:20 PM Valerio Pachera <valerio at pbds.eu> wrote:
> I was looking to substiture the cicle for e in new_d like this:
> [ new_d[e].append(k) if e in new_d else new_d[e].append(k) for e in d[k] ]
> but it can't work because 'new_d[e] = ' is missing.
Have a look at `dict.setdefault` and play around with it; I think it
will help you do what you want.
More information about the Tutor