Ranges as key for dictionary | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Ranges as key for dictionary

I played around with the Batman challenge. I was surprised that ranges as key work. But how to go on? It is experimental I just want to know, if this approach works. out={range(0,4):'I got this!', range(5,10):'Help me Batman', range(11,10000000):'Good Luck'}

27th Mar 2020, 6:42 PM
nichdiomajadoch
2 Answers
27th Mar 2020, 7:38 PM
Oma Falk
Oma Falk - avatar
+ 2
You can't do it like that, because the input will be one number, and you have only full ranges as keys in your dictionary. You would have to do something like (pseudo code)... if input in key: print(dict[key]) But if you do it like that, you could just as well just write: if 0<input<5: print(thatstring)
27th Mar 2020, 7:12 PM
HonFu
HonFu - avatar