I think OP's original example uses the conditions == 0, > 0 and < 0, so a hash table wouldn't work for 2 or -2.
== 0
> 0
< 0
2
-2
I think if you look closer, you'll see that my solution is equivalent in output to the OP's example.
Here's a nastier one (also with a py3 equivalent)
# python2 def really_silly(bar): return ["MAYBE","YES","NO"][cmp(bar,0)] # python3 def extremely_silly(bar): return ["MAYBE","YES","NO"][(bar>0)-(bar<0)]
God, I love how awful python can get sometimes!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I think OP's original example uses the conditions
== 0
,> 0
and< 0
, so a hash table wouldn't work for2
or-2
.I think if you look closer, you'll see that my solution is equivalent in output to the OP's example.
Here's a nastier one (also with a py3 equivalent)
God, I love how awful python can get sometimes!