Re: list() strange behaviour

2021-01-24 Thread jak
Il 20/12/2020 21:00, danilob ha scritto: Hi, I'm an absolute beginner in Python (and in English too ;-) Running this code: -- # Python 3.9.0 a = [[1, 2, 0, 3, 0], [0, 4, 5, 0, 6], [7, 0, 8, 0, 9], [2, 3, 0, 0, 1], [0, 0, 1, 8, 0]] b = ((x[0] for x in a))

Re: list() strange behaviour

2021-01-23 Thread Barry
until you stop asking. > > This is just a thought, not a request for such a feature. > > -Original Message- > From: Python-list On > Behalf Of ast > Sent: Saturday, January 23, 2021 2:54 AM > To: python-list@python.org > Subject: Re: list() strang

Re: list() strange behaviour

2021-01-23 Thread Chris Angelico
On Sun, Jan 24, 2021 at 8:49 AM Cameron Simpson wrote: > > On 23Jan2021 12:20, Avi Gross wrote: > >I am wondering how hard it would be to let some generators be resettable? > > > >I mean if you have a generator with initial conditions that change as it > >progresses, could it cache away those

Re: list() strange behaviour

2021-01-23 Thread Cameron Simpson
On 23Jan2021 12:20, Avi Gross wrote: >I am wondering how hard it would be to let some generators be resettable? > >I mean if you have a generator with initial conditions that change as it >progresses, could it cache away those initial conditions and upon some >signal, simply reset them? Objects

RE: list() strange behaviour

2021-01-23 Thread Avi Gross via Python-list
Of ast Sent: Saturday, January 23, 2021 2:54 AM To: python-list@python.org Subject: Re: list() strange behaviour Le 20/12/2020 à 21:00, danilob a écrit : > > > b = ((x[0] for x in a)) > There is a useless pair of parenthesis b = (x[0] for x in a) b is a GENERATOR expression

Re: list() strange behaviour

2021-01-23 Thread Terry Reedy
On 1/23/2021 2:54 AM, Unknown wrote: Le 20/12/2020 à 21:00, danilob a écrit : b = ((x[0] for x in a)) There is a useless pair of parenthesis b = (x[0] for x in a) b is a GENERATOR expression first list(b) calls next method on b repetedly until b is empty. So it provides the "content"

Re: list() strange behaviour

2021-01-22 Thread ast
Le 20/12/2020 à 21:00, danilob a écrit : b = ((x[0] for x in a)) There is a useless pair of parenthesis b = (x[0] for x in a) b is a GENERATOR expression first list(b) calls next method on b repetedly until b is empty. So it provides the "content" of b second list(b) provides nothing

Re: list() strange behaviour

2020-12-20 Thread Cameron Simpson
On 21Dec2020 08:09, Cameron Simpson wrote: >>b = ((x[0] for x in a)) > >This is a generator comprehension, and _not_ a list. I should amend this: a "generator _expression_", not comprehension. A "generator comprehension" is not a thing. Apologies, Cameron Simpson --

Re: list() strange behaviour

2020-12-20 Thread Cameron Simpson
On 20Dec2020 21:00, danilob wrote: >I'm an absolute beginner in Python (and in English too ;-) Well your English is far better than my very poor second language. >Running this code: >-- ># Python 3.9.0 > >a = [[1, 2, 0, 3, 0], > [0, 4, 5, 0, 6], > [7, 0, 8, 0, 9], > [2,

Re: list() strange behaviour

2020-12-20 Thread Tim Chase
On 2020-12-20 21:00, danilob wrote: > b = ((x[0] for x in a)) here you create a generator > print(list(b)) > [1, 0, 7, 2, 0] and then you consume all the things it generates here which means that when you go to do this a second time > print(list(b)) the generator is already empty/exhausted so

list() strange behaviour

2020-12-20 Thread danilob
Hi, I'm an absolute beginner in Python (and in English too ;-) Running this code: -- # Python 3.9.0 a = [[1, 2, 0, 3, 0], [0, 4, 5, 0, 6], [7, 0, 8, 0, 9], [2, 3, 0, 0, 1], [0, 0, 1, 8, 0]] b = ((x[0] for x in a)) print(list(b)) print(list(b)) ---