S
S
Sergey2018-10-01 21:13:29
Python
Sergey, 2018-10-01 21:13:29

How to get from the dictionary in which the dictionary and get the value from the 2 nested dictionaries by key?

car = {
    '321': [
        {'audi': 3, 'BMW': 4},
    ]

You need to get 4
If there are many similar lists and you need to add up, let's say all the values ​​\u200b\u200bthat with the key 'BMW': 4 can this be done through a loop?
PS I apologize if I called something wrong.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2018-10-01
@Serjdragonknight

it is possible through a loop
but pythonists use List Comprehensions
to get it simply
car['321'][0]['BMW']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question