How do I access the value of a specific element of a dictionary?

0

I have a tuple that contains lists as elements, and each list contains a tuple.

How could I access the individual value of each dictionary element?

The structure would be something like this:

mitupla[
 ({"Francia": "Paris", "Habitantes": 60000000}, true),
 ({"España": "Madrid", "Habitantes": 48000000}, false)
]

How could I access the value of France, Spain or true in Python?

    
asked by jae 22.12.2018 в 22:34
source

2 answers

1

to access, you have the following:

for t in mitupla:
    print(t[1]['pais'])

an observation, if you are creating the tuple the correct way would be {"Francia":"Paris", "Habitantes":60000000} instead that this {"pais": "Francia", "capital": "Paris", "Habitantes":60000000} so each value will have a key and it will be easier to access them

    
answered by 22.12.2018 в 23:04
-1

you can use this

for i in range(len(mitupla)):
    for j in range(len(mitupla[i])):
        midict1 = mitupla[i-1][j-1]   # Primer diccionario (francia)
        midict2 = mitupla[i][j-1]     # Segundo diccionario (españa)
for key in midict1:
    print(key)
for key in midict2:
    print(key)

this prints

Francia
Habitantes
España
Habitantes
    
answered by 22.12.2018 в 23:12