items()
to iterate over a dictionary PTC-W0011reaction_mapping.items()
to iterate over the dictionary163 view = discord.ui.View(timeout=None)
164 resulting_reactions_list = ""
165 async with ctx.channel.typing():
166 for r in reaction_mapping:167 resulting_reactions_list += f"Reaction {r} will give role <@&{reaction_mapping[r]}>\n"
168 view.add_item(ReactionRoleButton(
169 ctx.guild.get_role(reaction_mapping[r]), r))
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)