The question is, whether we can rely on behaviour of the reference implementation of python which contradicts its documentation:
list.extend(*iterable*) Extend the list by appending all the items from the iterable. Equivalent to a[len(a):] = iterable. sage: def f(n): ....: print(len(l)) ....: sage: l = []; l.extend(f(n) for n in range(3)) 0 1 2 sage: l = []; l[len(l):] = (f(n) for n in range(3)) 0 0 0 Martin Sébastien Labbé schrieb am Donnerstag, 10. Juni 2021 um 17:28:26 UTC+2: > > > 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/bfb8f395-28dd-4c90-b31f-948124e5ff6fn%40googlegroups.com.