[Tutor] R: Re: Create complex dictionary :p:
Mark Lawrence
breamoreboy at yahoo.co.uk
Tue Oct 27 18:38:47 EDT 2015
On 27/10/2015 21:37, jarod_v6--- via Tutor wrote:
> Sorry,
> I just realize my question are wrong: I want to knowhow to do dictionary of
> dictionary in most python way:
>
> diz = { "A"={"e"=2,"s"=10},"B"={"e"=20,"s"=7}}
>
> So I have some keys (A,B) is correlate with a new dictionary where I have
> other key I want to use. I want to extract for each key the "e" value.
> thanks
>
So having sorted out the dict syntax how about.
>>> diz = {"A":{"e":2,"s":10},"B":{"e":20,"s":7}}
>>> es = {}
>>> for k,v in diz.items():
... es[k] = v["e"]
...
>>> es
{'B': 20, 'A': 2}
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
More information about the Tutor
mailing list