2015-06-29

Things I don't like about python: bools indexing into a list

Things I don't like about python

Bools indexing into a list

This is valid code, and does what you expect:

list_ = [ 'A', 'B', 'C' ]
print list_[False]  # 'A'
print list_[True]   # 'B'

... which is neat, but it upsets me a little bit. You index into things with integers, not floats, not strings, and certainly not bools. This smells more like Javascript than Python. If I want to use a bool to index values out I can do that with a dict.

No comments:

Post a Comment