J
J
James_Obry2021-07-10 12:13:32
Python
James_Obry, 2021-07-10 12:13:32

How to find out how many elements and their values ​​are in the dictionary?

The bottom line is this, I have a dictionary called ad_featureswhich can have any number of elements with their values, the task is this: to pull out all its elements and their value from the dictionary
Please tell me how this can be implemented?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dmshar, 2021-07-10
@James_Obry

If "I have a dictionary" then it is absolutely incomprehensible how you managed to create it without understanding how to work with the dictionary? Just copied the finished code somewhere, or what?

dict = {'А': [173, 70], 'Б': 12345, 'С': 'Привет семье', 'D':{'D1':'Aу','D2':'[1,2,3]','D3':321}}
for itm in dict.items():
    print(itm)

Result:
('А', [173, 70])
('Б', 12345)
('С', 'Привет семье')
('D', {'D1': 'Aу', 'D2': '[1,2,3]', 'D3': 321})

I still recommend learning Python from books, not from videos.

A
Alan Gibizov, 2021-07-10
@phaggi

data = {'a':1, 'b': 2, 'c': 1}

for key in data:
    print(f'{key}: {data[key]}')
print(len(data), '\n')

for key in data.keys():
    print(f'{key}: {data[key]}')
print(len(data.keys()), '\n')

for key, value in data.items():
    print(f'{key}: {value}')
print(len(data.items()))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question