Fredrik Lundh wrote:
it could be worth expanding them to
"if x == 1 or x == 2 or x == 3:"
though...
C:\>timeit -s "a = 1" "if a in (1, 2, 3): pass"
1000 loops, best of 3: 0.11 usec per loop
C:\>timeit -s "a = 1" "if a == 1 or a == 2 or a == 3: pass"
1000 loops, best of 3: 0.0691 usec pe
On Sat, Feb 19, 2005, "Martin v. L?wis" wrote:
> Fredrik Lundh wrote:
>>
>>I'd say that this explains why it would still make sense to let the code
>>generator change
>>"x in (a, b, c)" to "x == a or x == b or x == c", as long as a, b, and c
>>are all integers.
>
> How often does that happen in
Fredrik Lundh wrote:
I'd say that this explains why it would still make sense to let the code
generator change
"x in (a, b, c)" to "x == a or x == b or x == c", as long as a, b, and c are
all integers.
How often does that happen in real code?
Regards,
Martin
__
At 04:45 PM 2/18/05 +0100, Fredrik Lundh wrote:
Phillip J. Eby wrote:
>>Only contains expressions are translated:
>>
>> "if x in [1,2,3]"
>>
>>currently turns into:
>>
>> "if x in (1,2,3)"
>>
>>and I'm proposing that it go one step further:
>>
>> "if x in Seachset([1,2,3])"
>
> ISTM tha
>> > Raymond then
>> translated
>> >
>> > for x in [1,2,3]:
>> >
>> > to
>> >
>> > for x in frozenset([1,2,3]):
Raymond> That's not right. for-statements are not touched.
Thanks for the correction. My apologies for the misstep.
Skip
At 10:15 AM 2/18/05 -0500, Raymond Hettinger wrote:
Only contains expressions are translated:
"if x in [1,2,3]"
currently turns into:
"if x in (1,2,3)"
and I'm proposing that it go one step further:
"if x in Seachset([1,2,3])"
ISTM that whenever I use a constant in-list like that, it's
> > Raymond then
> translated
> >
> > for x in [1,2,3]:
> >
> > to
> >
> > for x in frozenset([1,2,3]):
That's not right. for-statements are not touched.
> I may be missing something here (didn't follow the whole thread) but
> those two are not functionally equal.
> The docstring on fro
Skip Montanaro wrote:
I suggested that since the standard library code is commonly used as an
example of basic Python principles (that's probably not the right word), it
should uphold that ideal tuple/list distinction. Raymond then translated
for x in [1,2,3]:
to
for x in frozenset([1,2,3]
> I'm unclear why the list in "for x in [1,2,3]" or "if x not in
[1,2,3]"
> can't fairly easily be recognized as a constant and just be placed in
the
> constants array.
That part got done (at least for the if-statement).
The question is whether the type transformation idea should be carried a
st
>> Based on some ideas from Skip, I had tried transforming the likes of
>> "x in (1,2,3)" into "x in frozenset([1,2,3])"
Fredrik> savings in what? time or bytecode size? constructed
Fredrik> micro-benchmarks, or examples from real-life code?
Fredrik> do we have any stat
10 matches
Mail list logo