On 12/02/2010 10:39 AM, Mark Dickinson wrote:
On Nov 15, 12:46 pm, Tim Chase wrote:
On 11/15/2010 12:39 AM, Dmitry Groshev wrote:
x in range optimisation
I've often thought this would make a nice O(1)-test lookup on an
xrange() generator.
An O(1) test for 'x in' is implemented in Python 3
On Nov 15, 12:46 pm, Tim Chase wrote:
> On 11/15/2010 12:39 AM, Dmitry Groshev wrote:
>
> > x in range optimisation
>
> I've often thought this would make a nice O(1)-test lookup on an
> xrange() generator.
An O(1) test for 'x in ' is implemented in Python 3.2,
at least provided that x has type '
On Wed, 01 Dec 2010 15:18:32 -0800, Dmitry Groshev wrote:
> Here is a fresh example of what I meant by my first proposal. You need
> to build a matrix like this:
> 2 1 0 ...
> 1 2 1 ...
> 0 1 2 ...
> ...
> ... 1 2 1
> ... 0 1 2
> You could do this by one-liner:
> [[(2 - abs(x - y)) if it > 0 else
On Nov 22, 2:21 pm, Andreas Löscher wrote:
> > if x in range(a, b): #wrong!
> > it feels so natural to check it that way, but we have to write
> > if a <= x <= b
> > I understand that it's not a big deal, but it would be awesome to have
> > some optimisations - it's clearly possible to det
> if x in range(a, b): #wrong!
> it feels so natural to check it that way, but we have to write
> if a <= x <= b
> I understand that it's not a big deal, but it would be awesome to have
> some optimisations - it's clearly possible to detect things like that
> "wrong" one and fix it in a byt
Steven D'Aprano writes:
> >> Not everything needs to be a one liner. If you need this, do it the
> >> old- fashioned way:
> >>
> >> t = foo()
> >> if not pred(t): t = default_value
> >
> > I already explained how to write it as a one-liner:
> >
> > t = (lambda y: y if pred(y) else defau
On Thu, 18 Nov 2010 09:32:23 +, Mark Wooding wrote:
[...]
> You're wrong. Python evaluates these left-to-right, as I said.
> Parentheses override operator associativity; they don't affect
> evaluation order at all.
Fair enough. I concede your point.
[...]
>> Not everything needs to be a on
Steven D'Aprano writes:
> On Wed, 17 Nov 2010 16:31:40 +, Mark Wooding wrote:
>
> > But I don't think that's the big problem with this proposal. The real
> > problem is that it completely changes the evaluation rule for the
> > conditional expression. (The evaluation rule is already pretty
On Wed, 17 Nov 2010 16:31:40 +, Mark Wooding wrote:
> But I don't think that's the big problem with this proposal. The real
> problem is that it completely changes the evaluation rule for the
> conditional expression. (The evaluation rule is already pretty screwy:
> Python is consistently le
Christopher writes:
> i don't like magic names. what about:
>
> t = foo() as v if pred(v) else default_value
This is an improvement on `it'; anaphorics are useful in their place,
but they don't seem to fit well with Python.
But I don't think that's the big problem with this proposal. The real
On Wed, 17 Nov 2010 10:18:51 -0500 Mel wrote:
> Christopher wrote:
>
> >> ? Of course we can write it as
> >> t = foo() if pred(foo()) else default_value
> >> but here we have 2 foo() calls instead of one. Why can't we write
> >> just something like this:
> >> t = foo() if pred(it) else default_
Christopher wrote:
>> ? Of course we can write it as
>> t = foo() if pred(foo()) else default_value
>> but here we have 2 foo() calls instead of one. Why can't we write just
>> something like this:
>> t = foo() if pred(it) else default_value
>> where "it" means "foo() value"?
>
> i don't like mag
> ? Of course we can write it as
> t = foo() if pred(foo()) else default_value
> but here we have 2 foo() calls instead of one. Why can't we write just
> something like this:
> t = foo() if pred(it) else default_value
> where "it" means "foo() value"?
i don't like magic names. what about:
On Nov 14, 11:30 pm, alex23 wrote:
> On Nov 15, 4:39 pm, Dmitry Groshev wrote:
>
> > if x in range(a, b): #wrong!
>
> Only in Python 3.x, it's perfectly valid in Python 2.x. To achieve the
> same in Python 3.x, try:
>
> if x in list(range(a, b,)): # BUT SEE MY COMMENT BELOW
>
> > it feels
On Nov 15, 2:39 am, Dmitry Groshev 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
On 11/16/2010 3:42 AM, Steven D'Aprano wrote:
On Mon, 15 Nov 2010 22:40:00 -0700, Ian Kelly wrote:
On 11/15/2010 10:26 PM, Steven D'Aprano wrote:
t = foo()+bar()+baz() if pred(it) else baz()-foo()-bar()
What does "it" mean here?
"it" would mean the result of the expression foo()+bar()+baz()
On Mon, 15 Nov 2010 22:40:00 -0700, Ian Kelly wrote:
> On 11/15/2010 10:26 PM, Steven D'Aprano wrote:
>> t = foo()+bar()+baz() if pred(it) else baz()-foo()-bar()
>>
>> What does "it" mean here?
>
> "it" would mean the result of the expression foo()+bar()+baz(). What
> else could it mean?
It cou
On 11/15/2010 10:26 PM, Steven D'Aprano wrote:
t = foo()+bar()+baz() if pred(it) else baz()-foo()-bar()
What does "it" mean here?
"it" would mean the result of the expression foo()+bar()+baz(). What
else could it mean? There are valid objections to the proposal, but the
intended semantics
On Sun, 14 Nov 2010 22:39:05 -0800, Dmitry Groshev 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
On 11/14/2010 11:30 PM, alex23 wrote:
On Nov 15, 4:39 pm, Dmitry Groshev wrote:
First of all: how many times do you write something like
Second, I saw a lot of questions about using dot notation for a
"object-like" dictionaries and a lot of solutions like this:
class dotdict(dict):
On Nov 15, 2010, at 1:39 AM, Dmitry Groshev wrote:
>if x in range(a, b): #wrong!
> it feels so natural to check it that way, but we have to write
>if a <= x <= b
> I understand that it's not a big deal, but it would be awesome to have
> some optimisations - it's clearly possible to detect
On 11/15/2010 1:39 AM, Dmitry Groshev 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
Nev
On 11/15/2010 12:39 AM, Dmitry Groshev wrote:
x in range optimisation
I've often thought this would make a nice O(1)-test lookup on an
xrange() generator. I don't have strong use-cases for it, but a
bit of well-tested code in the standard library would save me
from doing the math (along wit
Dmitry Groshev writes:
> First of all: how many times do you write something like
> t = foo()
> t = t if pred(t) else default_value
> ? Of course we can write it as
> t = foo() if pred(foo()) else default_value
> but here we have 2 foo() calls instead of one. Why can't we write just
>
Dmitry Groshev writes:
> which looks almost like a natural language. But there is some
> pitfalls:
> if x in range(a, b): #wrong!
> it feels so natural to check it that way, but we have to write
> if a <= x <= b
For the record, you have to write:
if a <= x < b:
Ranges are open on t
On Nov 15, 12:03 pm, alex23 wrote:
> On Nov 15, 5:50 pm, Dmitry Groshev wrote:
>
> > On Nov 15, 10:30 am, alex23 wrote:
> > > Personally, I like keeping object attribute references separate from
> > > dictionary item references.
>
> > Your Python doesn't - dot notation is just a sugar for __dict
On Nov 15, 5:50 pm, Dmitry Groshev wrote:
> On Nov 15, 10:30 am, alex23 wrote:
> > Personally, I like keeping object attribute references separate from
> > dictionary item references.
>
> Your Python doesn't - dot notation is just a sugar for __dict__ lookup
> with default metaclass.
That's a gr
On Nov 15, 10:30 am, alex23 wrote:
> On Nov 15, 4:39 pm, Dmitry Groshev wrote:
>
> > First of all: how many times do you write something like
> > t = foo()
> > t = t if pred(t) else default_value
> > ? Of course we can write it as
> > t = foo() if pred(foo()) else default_value
> > bu
On Nov 15, 5:30 pm, alex23 wrote:
> t = foo(x) if else default
This should read 'test' instead of 'text', sorry.
--
http://mail.python.org/mailman/listinfo/python-list
On Nov 15, 4:39 pm, Dmitry Groshev wrote:
> First of all: how many times do you write something like
> t = foo()
> t = t if pred(t) else default_value
> ? Of course we can write it as
> t = foo() if pred(foo()) else default_value
> but here we have 2 foo() calls instead of one. Why can
On Nov 15, 9:48 am, Chris Rebert wrote:
> On Sun, Nov 14, 2010 at 10:39 PM, Dmitry Groshev
> 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.
>
> > Second, I saw a lot of questions about using do
On Sun, Nov 14, 2010 at 10:39 PM, Dmitry Groshev 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.
> Second, I saw a lot of questions about using dot notation for a
> "object-like" dictionaries and a lo
On Nov 15, 9:39 am, Dmitry Groshev 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
>
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
? Of course we can write it as
t = foo() if pred(f
34 matches
Mail list logo