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'}
2 Respuestas
+ 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)