Re: List comprehension strangeness

2019-07-22 Thread Gregory Ewing
Nicholas Cole wrote: [x.id for x in some_function()] According to the profiler, some_function was being called 52,000 times Is some_function recursive, by any chance? -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: List comprehension strangeness

2019-07-22 Thread Bob Gailer
The length of the list produced by the comprehension also give you good information. -- https://mail.python.org/mailman/listinfo/python-list

Re: List comprehension strangeness

2019-07-22 Thread Chris Angelico
On Mon, Jul 22, 2019 at 11:33 PM Nicholas Cole wrote: > > I was profiling a slow function in an application last week, and came > across something that I still can’t explain. Inside a loop that was being > called 4 times, inside a for loop that ran for a few dozen times there was > a list compress

Re: List comprehension strangeness

2019-07-22 Thread Bob Gailer
The function IMHO must be returning a generator. I would look for a problem in the generator code. -- https://mail.python.org/mailman/listinfo/python-list

Re: List comprehension strangeness

2019-07-22 Thread Calvin Spealman
It is impossible to diagnose without seeing more context. Specifically, you'll need to share the code around this line. The whole function, preferably. On Mon, Jul 22, 2019 at 9:31 AM Nicholas Cole wrote: > I was profiling a slow function in an application last week, and came > across something

List comprehension strangeness

2019-07-22 Thread Nicholas Cole
I was profiling a slow function in an application last week, and came across something that I still can’t explain. Inside a loop that was being called 4 times, inside a for loop that ran for a few dozen times there was a list compression of the form: [x.id for x in some_function()] According to t