Ask coding questions

← Back to all posts
Using an entire dict for one elif/if statement
svensk007 (58)

So im working on this project right now and there is part of it where I have an elif [command typed] != [dict]: but I can't figure out how to use the whole dict so I don't have to type out like 30 more elif statements.

Comments
hotnewtop
[deleted]

You can loop by doing this

for key in a_dict:
print(key, '->', a_dict[key])

this article

[deleted]

Why don’t you use a for loop to loop through the entire dict? Also next time can you specify what language.

svensk007 (58)

@TestOP its python
I'm making like a terminal type thing with commands you type in and it will output them

svensk007 (58)

@TestOP also could you explain this better because you can't put a for i in range(blah blah blah) inside of a dict

[deleted]

@svensk007 yeah on sec I’m on a phone right now and about to leave so