items()
to iterate over a dictionary PTC-W0011text_apis_data.items()
to iterate over the dictionary80
81
82# Command help section
83for x in text_apis_data:84 add_command_help(
85 "text",
86 [
cf_api_data.items()
to iterate over the dictionary73
74
75# Command help section
76for x in cf_api_data:77 add_command_help(
78 "anime_cf",
79 [
special_emojis_dict.items()
to iterate over the dictionary55 [".earth `or` .globe", "Make the world go round."],
56]
57
58for x in special_emojis_dict:59 special_emoji_help.append([f".{x}", special_emojis_dict[x]["help"]])
60
61add_command_help("emoji", special_emoji_help)
The preferred way to iterate over the key-value pairs of a dictionary is to declare two variables in a for loop, and then call dictionary.items()
(or dictionary.iteritems()
for Python2), where dictionary is the name of your variable representing a dictionary.'
details = {"first_name": "Alfred", "last_name":"Hitchcock"}
for key in details.keys():
print(key, d[key])
details = {"first_name": "Alfred", "last_name":"Hitchcock"}
for key, value in details.items():
print(key, value)