Re: Is there a better way to create a list of None objects?

2021-08-12 Thread Dennis Lee Bieber
On Thu, 12 Aug 2021 09:57:33 +0100, Stephen Tucker declaimed the following: > ># Logic Effect > ># > ># [None * 8]TypeError: unsupported operand type(s) for *: ... > ># [(None) * 8] TypeError: unsupported operand type(s) for *: ... > ># [((None)) * 8]TypeError: unsup

Re: Is there a better way to create a list of None objects?

2021-08-12 Thread Stephen Tucker
Thanks for this feedback, Chris, Matthieu. Both are spot on - and thanks for the timing comparison, Matthieu. I suppose I didn't think to try the solution you suggest because I didn't think that I would end up with a single list, but 8 of them. OK, I'll stop wriggling. Stephen. On Thu, Aug 12, 2

Re: Is there a better way to create a list of None objects?

2021-08-12 Thread Matthieu Dartiailh
You can achieve the same result by writing: [None] * 8 Comparing both cases in IPython I get: In [1]: %timeit list((None,)*8) 110 ns ± 0.785 ns per loop (mean ± std. dev. of 7 runs, 1000 loops each) In [2]: %timeit [None] * 8 88.2 ns ± 0.432 ns per loop (mean ± std. dev. of 7 runs, 1000

Re: Is there a better way to create a list of None objects?

2021-08-12 Thread Chris Angelico
On Thu, Aug 12, 2021 at 6:59 PM Stephen Tucker wrote: > > Hi, > > I thought I'd share the following piece of code that I have recently written > (a) to check that what I have done is reasonable - even optimum, > (b) to inform others who might be wanting to do similar things, and > (c) to invite co

Is there a better way to create a list of None objects?

2021-08-12 Thread Stephen Tucker
Hi, I thought I'd share the following piece of code that I have recently written (a) to check that what I have done is reasonable - even optimum, (b) to inform others who might be wanting to do similar things, and (c) to invite comment from the community. -