On Mon, Jul 30, 2018 at 1:08 PM Alan Gauld via Tutor <tutor@python.org> wrote: > There are lots of options including those suggested elsewhere. > Another involves using get() which makes your function > look like: > > def viceversa(d): > new_d = dict() > for k in d: > for e in d[k]: > new_d[e] = new_d.get(e,[]).append(k)
Note that this will set each entry to `None` as returned by `list.append`. -- Zach _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor