On Thursday, June 10, 2021 at 9:54:15 AM UTC+2 axio...@yahoo.de wrote:

> While working on https://trac.sagemath.org/ticket/31897 Tejasvi (gsoc21) 
> and I stumbled across the following python behaviour:
>
> sage: def f(n):
> ....:     print(len(l))
> ....:     
> sage: l = []; l.extend(f(n) for n in range(3))
> 0
> 1
> 2
> sage: l = []; l.extend([f(n) for n in range(3)])
> 0
> 0
> 0
>
> Is this behaviour we can rely on?  I could not find in the python doc, in 
> any case.
>
>
In the second example, the list [f(n) for n in range(3)] is created before 
the method extend is called which explains why 0 is printed 3 times.

What is the question?

Sébastien

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/802c1d06-d169-4194-91f6-5a63d3b70b02n%40googlegroups.com.

Reply via email to