+ 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

3rd May 2018, 2:44 PM
Çůřîöş ßąšäñț 🇮🇳
Çůřîöş ßąšäñț 🇮🇳 - avatar
5 ответов
+ 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.
3rd May 2018, 2:59 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 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
3rd May 2018, 2:47 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 6
There you go - two different approaches to the problem: https://code.sololearn.com/cYAaY74v0cUk/?ref=app
3rd May 2018, 3:21 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
0
Have a look on the code, plz
3rd May 2018, 2:48 PM
Çůřîöş ßąšäñț 🇮🇳
Çůřîöş ßąšäñț 🇮🇳 - avatar
0
Can you please give me a example.
3rd May 2018, 3:05 PM
Çůřîöş ßąšäñț 🇮🇳
Çůřîöş ßąšäñț 🇮🇳 - avatar