Inverse of dict(zip(x,y))
Andre Engels
andreengels at gmail.com
Wed Mar 4 05:16:34 EST 2009
On Wed, Mar 4, 2009 at 11:02 AM, lone_eagle <icymist at gmail.com> wrote:
> Can someone suggest a easy method to do the inverse of dict(zip(x,y))
> to get two lists x and y?
>
> So, if x and y are two lists, it is easier to make a dictionary using
> d = dict(zip(x,y)), but if I have d of the form, d = {x1:y1,
> x2:y2, ...}, what is there any trick to get lists x = [x1, x2, ...]
> and y = [y1, y2, ...]
x = d.keys()
y = [d[e] for d in x]
y = d.values() might also work, but I am not sure whether d.keys() and
d.values() are guaranteed to use the same order.
--
André Engels, andreengels at gmail.com
More information about the Python-list
mailing list