+ 1
How do I introduce two keys in dictionary?
I want to print a value according to two different keys? For example open the code below! https://code.sololearn.com/cQboXp5HhyKd/?ref=app
5 Respuestas
+ 7
Aha, if so, I'd recommend using dict(zip(keys, values)) syntax. Both keys and values may be iterables, so that zip assigns the latter to the former.
Or, if those key pairs are logically connected somehow (like small and capital letters), you may use a list expression to construct the keys list on the fly.
+ 6
You can have a tuple as a key, if that's what you mean.
d = {(0, 0): "zero", (0, 1): "one", (1, 0): "one", (1, 1): "two"}
print(d[(0,0)])
>>>
zero
+ 6
There you go - two different approaches to the problem:
https://code.sololearn.com/cYAaY74v0cUk/?ref=app
0
Have a look on the code, plz
0
Can you please give me a example.