Skip to content

Instantly share code, notes, and snippets.

@reox
Last active March 28, 2016 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reox/3ce17db8db831b933cf8 to your computer and use it in GitHub Desktop.
Save reox/3ce17db8db831b933cf8 to your computer and use it in GitHub Desktop.
Get the latest version of folders named like v23.42.1337
versions = filter(lambda x: re.match(r"^v[0-9]+\.[0-9]+\.[0-9]+$", x), os.listdir(path))
# The short form for:
# Take the version code like 1.2.197 and create a number out of it: 100020197 (every code part has 4 digits)
# Then sort it numerically and take the last one, which should be the largest number
last_version = sorted(versions, key=lambda x: sum(map(lambda x: 10 ** ((2-x[0]) * 4) * x[1], enumerate(map(int, x[1:].split("."))))))[-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment