examples: improve finding last checkpoint in "checkpoint.py"
This is a python example. We should do nice things, like using max() for finding the maximum, instead of sorting.
This commit is contained in:
@@ -71,11 +71,11 @@ def find_checkpoint(nmc, path):
|
|||||||
|
|
||||||
|
|
||||||
def find_checkpoint_last(nmc):
|
def find_checkpoint_last(nmc):
|
||||||
l = [c.get_path() for c in nmc.get_checkpoints()]
|
return max(
|
||||||
if not l:
|
nmc.get_checkpoints(),
|
||||||
return None
|
key=lambda c: checkpoint_path_to_num(c.get_path()),
|
||||||
l.sort(key=checkpoint_path_to_num)
|
default=None,
|
||||||
return l[-1]
|
)
|
||||||
|
|
||||||
|
|
||||||
def validate_path(path, nmc):
|
def validate_path(path, nmc):
|
||||||
|
Reference in New Issue
Block a user