Fixed #23968 -- Replace list comprehension with generator comprehension when possible

Having a `[` followed by a  `(` on the next line makes the code a bit move difficult to read and the performance benefit is absolutely negligible here as the result is cached.