Comprehension To Generator

Python pattern

Replace unneeded list comprehensions with direct generators.


Apply with the Grit CLI
grit apply comp_to_generator

Comprehension to generator

BEFORE
hat_found = any([is_hat(item) for item in wardrobe])
hat_found = list([is_hat(item) for item in wardrobe])

hat_found = dict([(item, is_hat(item)) for item in wardrobe])
AFTER
hat_found = any(is_hat(item) for item in wardrobe)
hat_found = list(is_hat(item) for item in wardrobe)

hat_found = dict([(item, is_hat(item)) for item in wardrobe])