Re: list slice and generators

2015-11-25 Thread Pavlos Parissis
On 25/11/2015 11:07 πμ, Peter Otten wrote: > Pavlos Parissis wrote: > >> Hi, >> >> Do you see any possible dangerous hidden bug in the below code(using >> python2.7 and python3.4)? >> >> My goal is to avoid go through the metrics list twice. But, I don't >> know if there will be a problem with doi

Re: list slice and generators

2015-11-25 Thread Peter Otten
Ian Kelly wrote: > On Wed, Nov 25, 2015 at 10:44 AM, Ian Kelly wrote: >> On Wed, Nov 25, 2015 at 3:07 AM, Peter Otten <__pete...@web.de> wrote: elif name in METRICS_AVG: >>> # writing a function that calculates the average without >>> # materialising the list left as

Re: list slice and generators

2015-11-25 Thread Peter Otten
Ian Kelly wrote: >>assert metrics > > metrics is always going to be an itertools.chain object at this > assert, so how could the assertion ever fail? Should an assertion ever fail? >From your reaction I conclude that it was puzzling and a comment like # always true in a boolean context would

Re: list slice and generators

2015-11-25 Thread Ian Kelly
On Wed, Nov 25, 2015 at 10:44 AM, Ian Kelly wrote: > On Wed, Nov 25, 2015 at 3:07 AM, Peter Otten <__pete...@web.de> wrote: >>> elif name in METRICS_AVG: >> # writing a function that calculates the average without >> # materialising the list left as an exercise ;) > >

Re: list slice and generators

2015-11-25 Thread Ian Kelly
On Wed, Nov 25, 2015 at 3:07 AM, Peter Otten <__pete...@web.de> wrote: > to get down to one intermediate list. Avoiding the last one is a bit tricky: > > metrics = (converter(x.metric(name)) for x in self._server_per_proc) > metrics = (x for x in metrics if x is not None) > try: > # if there is

Re: list slice and generators

2015-11-25 Thread Peter Otten
Pavlos Parissis wrote: > Hi, > > Do you see any possible dangerous hidden bug in the below code(using > python2.7 and python3.4)? > > My goal is to avoid go through the metrics list twice. But, I don't > know if there will be a problem with doing in place replace of list > elements using 2 gener

list slice and generators

2015-11-24 Thread Pavlos Parissis
Hi, Do you see any possible dangerous hidden bug in the below code(using python2.7 and python3.4)? My goal is to avoid go through the metrics list twice. But, I don't know if there will be a problem with doing in place replace of list elements using 2 generators. # metrics = ['', '0', '10']