-
Notifications
You must be signed in to change notification settings - Fork 311
One more nit on all_equal() #902
Copy link
Copy link
Closed
Description
I missed something during the code review. There is an extra unnecessary next call in the first for-loop. This is easily solved by adding another return True.
def all_equal(iterable, key=None):
iterator = groupby(iterable, key)
for first in iterator:
for second in iterator:
return False
return True # <== This was missed
return True
For example, all_equal('a') calls the groupby.__next__ three times.
This is can be made visible by replacing groupby with verbose_groupby:
class verbose_groupby(itertools.groupby):
def __next__(self):
print('N')
return super().__next__()
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels