How to loop through the dictionary keys in Python - example

preview_player
Показать описание
Hi again.
In this lesson we're going to talk about that how to loop through the dictionary keys in Python.
Рекомендации по теме
Комментарии
Автор

I'm afraid that both of you are mistaken here. That's not a dictionary or a list. That is a set.

If it were an actual dictionary, with key/value pairs, you could iterate on it to get a list of keys. You could also get keys and values with something like:

for key in my_dict:
print( key, my_dict[key]

Though, it's more efficient (especially for larger dictionaries) to use something like:

for key, value in my_dict.items():
print( key, value)

claffert
join shbcf.ru