Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve time complexity by using filter()
  • Loading branch information
oscar-LT authored and ethanfurman committed Jun 22, 2022
commit c3e91e80a246b87e450cf9879c9cffeb27872e0f
19 changes: 11 additions & 8 deletions Lib/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -1214,15 +1214,18 @@ def _generate_next_value_(name, start, count, last_values):
count: the number of existing members
last_values: the list of values assigned
"""
incrementable_last_values = []
for val in last_values:
try:
incrementable_last_values.append(val + 1)
except TypeError:
pass

if incrementable_last_values:
return sorted(incrementable_last_values)[-1]
# Filter funciton to deal with last_values lists of mixed types
def test_incrementable(n):
try:
n + 1
return True
except:
return False

checked_last_values = sorted(filter(test_incrementable, last_values))
if checked_last_values:
return checked_last_values[-1] + 1
else:
return start

Expand Down