Not this one the other one, from a dictionary

Sion Arrowsmith sion at viridian.paintbox
Tue Sep 22 08:01:37 EDT 2009


Vlastimil Brom  <vlastimil.brom at gmail.com> wrote:
>>>> other_key = (set(data_dict.iterkeys()) - set([not_wanted_key,])).pop()

other_key = set(data_dict.iterkeys()).difference([not_wanted]).pop()
saves you the construction of an unnecessary set instance. At the
cost of a bit more verbosity, you can get rid of a second set:

key_set = set(data_dict.iterkeys())
key_set.difference_update([not_wanted_key])
other_key = key_set.pop()

although the loss of clarity compared to the one liner can't be
worth the miniscule benefit in this case.

-- 
\S

   under construction




More information about the Python-list mailing list