Some syntactic sugar proposals
andre.roberge at gmail.com
Tue Nov 16 19:45:00 CET 2010
On Nov 15, 2:39 am, Dmitry Groshev <lambdadmi... at gmail.com> wrote:
> Here are some proposals. They are quite useful at my opinion and I'm
> interested for suggestions. It's all about some common patterns.
> First of all: how many times do you write something like
> t = foo()
> t = t if pred(t) else default_value
> And the third. The more I use python the more I see how "natural" it
> can be. By "natural" I mean the statements like this:
> [x.strip() for x in reversed(foo)]
> which looks almost like a natural language. But there is some
> if x in range(a, b): #wrong!
This is true only if x is an integer such that a <= x < b
> it feels so natural to check it that way, but we have to write
> if a <= x <= b
This is true if x is an integer OR a float. Two very different
cases, deserving of different notation.
More information about the Python-list