I found a relevant discussion. Bad news, it seems. https://stackoverflow.com/questions/57194152/is-python-list-extenditerator-guaranteed-to-be-lazy
Martin R schrieb am Donnerstag, 10. Juni 2021 um 10:20:23 UTC+2: > Thank you for the pointer, but of course I looked it up before posting. > It says > > list.extend(*iterable*) > > Extend the list by appending all the items from the iterable. Equivalent > to a[len(a):] = iterable. > However, this description is simply not true: > > sage: l = []; l[len(l):] = (f(n) for n in range(3)) > 0 > 0 > 0 > > dim...@gmail.com schrieb am Donnerstag, 10. Juni 2021 um 10:10:12 UTC+2: > >> >> >> On Thu, 10 Jun 2021, 08:54 'Martin R' via sage-devel, < >> sage-...@googlegroups.com> 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. >>> >> >> see https://docs.python.org/3/tutorial/datastructures.html >> >>> >>> Martin >>> >>> -- >>> 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+...@googlegroups.com. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/sage-devel/53c97d28-fc5e-43ee-9371-bf8d2b646554n%40googlegroups.com >>> >>> <https://groups.google.com/d/msgid/sage-devel/53c97d28-fc5e-43ee-9371-bf8d2b646554n%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> -- 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/d15eb99d-b9b0-4ff5-8f6d-fd0a29b2cf21n%40googlegroups.com.