summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-05-02 18:02:50 +0200
committerThomas Haller <thaller@redhat.com>2022-05-02 18:04:37 +0200
commit3ce3ed4c92fb7d21da8f8c2f77b093fa71130455 (patch)
tree520ecb76bdfa7145654f17405a1c6a73a8ba7c34
parent6a04bcc59d4bdcb545353071ecc4891570e9f4e2 (diff)
downloadNetworkManager-3ce3ed4c92fb7d21da8f8c2f77b093fa71130455.tar.gz
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.
-rwxr-xr-xexamples/python/gi/checkpoint.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/examples/python/gi/checkpoint.py b/examples/python/gi/checkpoint.py
index b63b1c37a4..6f3194cdb1 100755
--- a/examples/python/gi/checkpoint.py
+++ b/examples/python/gi/checkpoint.py
@@ -71,11 +71,11 @@ def find_checkpoint(nmc, path):
def find_checkpoint_last(nmc):
- l = [c.get_path() for c in nmc.get_checkpoints()]
- if not l:
- return None
- l.sort(key=checkpoint_path_to_num)
- return l[-1]
+ return max(
+ nmc.get_checkpoints(),
+ key=lambda c: checkpoint_path_to_num(c.get_path()),
+ default=None,
+ )
def validate_path(path, nmc):