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