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

You can use a dict comprehension here, too.