RE: Dict comp help

Discussion in 'Python' started by Joseph L. Casale, Jan 24, 2013.

  1. > >>> data = [{'a': 'xx', 'b': 'yy', 'c': 'zz'},  {'a': 'dd', 'b': 'ee', 'c': 'ff'}] 
    > >>> {d["a"]: d["c"] for d in data}

    > {'xx': 'zz', 'dd': 'ff'}

    That is exactly what I needed, for which I certainly over complicated!

    Thanks everyone!
    Joseph L. Casale, Jan 24, 2013
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page