I filter a location for entities other than the player:
entities = filter(lambda entity: entity != player, location.entities)
If there are any entities, print each one of them:
if any(entities):
print('Entites nearby:')
for entity in entities:
print(entity)
However, using any()
consumes the elements in the generator, as the subsequent for loop iterates zero times.
Is there a way to check if a generator is empty or check its length without resorting to lists or having to manually reset the iterator?