2011年(264)
分类: Python/Ruby
2011-05-27 14:47:59
The one limitation that most disappoints me is that Python lacks is a functional way of writing if/else. Sometimes you just want to do something like this:
lambda x : if_else(x>100, “big number”, “little number”)
(This would return the string “big number” if x was greater than 100, and “little number” otherwise.) Sometimes I get around this by defining my own if_else that I can use in lambda-functions:
def if_else(condition, a, b) : if condition : return a else : return b