Wow, thank you Ian for this very detailed answer, and thank you for taking the
time for that! Much appreciated!
If I get this right, I have to somehow fix the value of a_list during the loop,
like when you use the classic default value argument trick with lambdas (damn, I
should have thought of th
Le 14/03/19 à 10:45, Peter Otten a écrit :
> Pierre Reinbold wrote:
>
>> Wow, thank you Ian for this very detailed answer, and thank you for taking
>> the time for that! Much appreciated!
>>
>> If I get this right, I have to somehow fix the value of a_list during the
>> loop, like when you use the
Pierre Reinbold wrote:
> Wow, thank you Ian for this very detailed answer, and thank you for taking
> the time for that! Much appreciated!
>
> If I get this right, I have to somehow fix the value of a_list during the
> loop, like when you use the classic default value argument trick with
> lambda
Wow, thank you Ian for this very detailed answer, and thank you for taking the
time for that! Much appreciated!
If I get this right, I have to somehow fix the value of a_list during the loop,
like when you use the classic default value argument trick with lambdas (damn, I
should have thought of th
You're basically running into this:
https://docs.python.org/3/faq/programming.html#why-do-lambdas-defined-in-a-loop-with-different-values-all-return-the-same-result
To see why, let's try disassembling your function. I'm using Python 3.5
here, but it shouldn't make much of a difference.
py> import
I see. Thanks for the clarification.
On Dec 22, 12:35 am, Steven D'Aprano wrote:
> On Wed, 21 Dec 2011 21:45:13 -0800, GZ wrote:
> > Now the question here is this:
>
> > def h():
> > if condition=true:
> > #I would like to return an itereator with zero length
> > else:
> > f
On Wed, 21 Dec 2011 21:45:13 -0800, GZ wrote:
> Now the question here is this:
>
> def h():
> if condition=true:
>#I would like to return an itereator with zero length
> else:
>for ...: yield x
>
> In other words, when certain condition is met, I want to yield nothing.
>
On Thu, Dec 22, 2011 at 4:45 PM, GZ wrote:
> def h():
> if condition=true:
> #I would like to return an itereator with zero length
> else:
> for ...: yield x
Easy. Just 'return' in the conditional.
>>> def h():
if condition:
return
for i in range
On Wed, 21 Dec 2011 21:45:13 -0800, GZ wrote:
> Hi,
>
> I am wondering what would be the best way to return an iterator that has
> zero items.
return iter([])
> I just noticed the following two are different:
>
> def f():
>pass
That creates a function that does nothing, and then returns
On Wed, 22 Dec 2010 15:49:31 -0800, Dan Stromberg wrote:
> def generator():
> i = 0
> while True:
> yield i
> i += 1
Shorter version:
from itertools import count as generator
--
http://mail.python.org/mailman/listinfo/python-list
Dan Stromberg wrote:
> You likely want a class variable:
Sounds like an elegant solution. Thanks!
Victor.
--
Victor Eijkhout -- eijkhout at tacc utexas edu
--
http://mail.python.org/mailman/listinfo/python-list
On Wed, Dec 22, 2010 at 3:15 PM, Victor Eijkhout wrote:
> So I have a generator, either as a free function or in a class and I
> want to generate objects that are initialized from the generated things.
>
> def generator():
> for whatever:
> yield something
> class Object():
>
On 12/22/2010 3:15 PM Victor Eijkhout said...
So I have a generator, either as a free function or in a class and I
want to generate objects that are initialized from the generated things.
def generator():
for whatever:
yield something
class Object():
def __init
Mathias Panzenboeck wrote:
> Robert Kern wrote:
>> Timothy Wu wrote:
>>> Hi,
>>>
>>> Using generator recursively is not doing what I expect:
>>>
>>> def test_gen(x):
>>> yield x
>>> x = x - 1
>>> if x != 0:
>>> test_gen(x)
>>
>> The only thing that the last line does is *creat
Robert Kern wrote:
> Timothy Wu wrote:
>> Hi,
>>
>> Using generator recursively is not doing what I expect:
>>
>> def test_gen(x):
>> yield x
>> x = x - 1
>> if x != 0:
>> test_gen(x)
>
> The only thing that the last line does is *create* a new generator object. You
> need to a
On 11/26/06, Robert Kern <[EMAIL PROTECTED]> wrote:
The only thing that the last line does is *create* a new generator object.
You
need to actually iterate over it and yield its values. E.g.
In [2]: def test_gen(x):
...: yield x
...: x -= 1
...: if x != 0:
...:
Timothy Wu wrote:
> Hi,
>
> Using generator recursively is not doing what I expect:
>
> def test_gen(x):
> yield x
> x = x - 1
> if x != 0:
> test_gen(x)
The only thing that the last line does is *create* a new generator object. You
need to actually iterate over it and yield
17 matches
Mail list logo