Stian Soiland wrote:
På 14. jan 2005 kl. 22:58 skrev Steven Bethard:
(Any mac users? How do I fix this to appear in Norwegian? =)
Note that if you're not comfortable with short-circuiting behavior,
you can also code this using lazy evaluation:
(lambda: 1/x, lambda: 1.0e99)[x==0]()
.. and peo
På 14. jan 2005 kl. 22:58 skrev Steven Bethard:
(Any mac users? How do I fix this to appear in Norwegian? =)
Note that if you're not comfortable with short-circuiting behavior,
you can also code this using lazy evaluation:
(lambda: 1/x, lambda: 1.0e99)[x==0]()
.. and people wonder why so many
Steven Bethard wrote:
> It's me wrote:
>> Say again???
>
> Please stop top-posting -- it makes it hard to reply in context.
>
>> "Reinhold Birkenfeld" wrote...
>>>It's me wrote:
If this is true, I would run into trouble real quick if I do a:
(1/x,1.0e99)[x==0]
>>>
>>>Lazy evaluation:
It's me wrote:
Say again???
Please stop top-posting -- it makes it hard to reply in context.
"Reinhold Birkenfeld" wrote...
It's me wrote:
If this is true, I would run into trouble real quick if I do a:
(1/x,1.0e99)[x==0]
Lazy evaluation: use the (x==0 and 1e99 or 1/x) form!
If you want short-circu
It's me wrote:
> Say again???
>
> "Reinhold Birkenfeld" <[EMAIL PROTECTED]> wrote in
> message news:[EMAIL PROTECTED]
>> It's me wrote:
>> > Sorry if my question was a little "lazy" and yes, I was asking about the
>> > "lazy evaluation". :=)
>> >
>> > I am surprised about this (and this can be da
Say again???
"Reinhold Birkenfeld" <[EMAIL PROTECTED]> wrote in
message news:[EMAIL PROTECTED]
> It's me wrote:
> > Sorry if my question was a little "lazy" and yes, I was asking about the
> > "lazy evaluation". :=)
> >
> > I am surprised about this (and this can be dangerous, I guess).
> >
> > I
It's me wrote:
> Sorry if my question was a little "lazy" and yes, I was asking about the
> "lazy evaluation". :=)
>
> I am surprised about this (and this can be dangerous, I guess).
>
> If this is true, I would run into trouble real quick if I do a:
>
> (1/x,1.0e99)[x==0]
>
> and that's not g
Because you can't take the len() of an integer. Try casting a as a str:
b=(1,len(str(a)))[isinstance(a,(list,tuple,dict))]
-Original Message-
From: It's me [mailto:[EMAIL PROTECTED]
Sent: Wednesday, January 12, 2005 12:35 PM
To: python-list@python.org
Subject: Why would I get
It's me wrote:
For this code snip:
a=3
b=(1,len(a))[isinstance(a,(list,tuple,dict))]
Why would I get a TypeError from the len function?
You're looking for lazy evaluation or short-circuiting behavior. Python
provides one form of short circuiting behavior with 'and' and 'or',
though you need
"Peter Hansen" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> What did you expect the "length" of the integer 3 to be?
Perhaps 2 (bits in a minimal binary representation).
I once, for maybe a minute, considered proposing this as an overloaded
meaning of len, but realized that th
It's me wrote:
For this code snip:
a=3
.
b=(1,len(a))[isinstance(a,(list,tuple,dict))]
Why would I get a TypeError from the len function?
Thanks,
because the interpreter evaluates the tuple (1, len(a)) before applying
the indexing to it.
You are trying to be far too clever. The standard way
Sorry if my question was a little "lazy" and yes, I was asking about the
"lazy evaluation". :=)
I am surprised about this (and this can be dangerous, I guess).
If this is true, I would run into trouble real quick if I do a:
(1/x,1.0e99)[x==0]
and that's not good.
Something to keep in mind. :
It's me wrote:
For this code snip:
a=3
b=(1,len(a))[isinstance(a,(list,tuple,dict))]
Why would I get a TypeError from the len function?
What did you expect the "length" of the integer 3 to be?
-Peter
--
http://mail.python.org/mailman/listinfo/python-list
On 12.01.2005, at 18:35, It's me wrote:
For this code snip:
a=3
b=(1,len(a))[isinstance(a,(list,tuple,dict))]
Why would I get a TypeError from the len function?
the problem is, that (1,len(a)) is evaluated, neither what type a
actually has
(python has no builtin lazy evaluation like ML). You
On 12.01.2005, at 18:35, It's me wrote:
For this code snip:
a=3
b=(1,len(a))[isinstance(a,(list,tuple,dict))]
Why would I get a TypeError from the len function?
because len() works only for sequence and mapping objects:
>>> help(len)
Help on built-in function len in module __builtin__:
len(...
For this code snip:
a=3
b=(1,len(a))[isinstance(a,(list,tuple,dict))]
Why would I get a TypeError from the len function?
Thanks,
--
http://mail.python.org/mailman/listinfo/python-list
16 matches
Mail list logo