Skip to content

Instantly share code, notes, and snippets.

@Nagasaki45
Created May 24, 2016 08:40
Show Gist options
  • Save Nagasaki45/6e585bbbcc1681a468bc7ce4df76411b to your computer and use it in GitHub Desktop.
Save Nagasaki45/6e585bbbcc1681a468bc7ce4df76411b to your computer and use it in GitHub Desktop.
Pick the filename with the largest <a> value from files like "file_<a>.<b>.npy.gz"
import os
import re
re_pattern = r'file_(?P<a>[0-9]*)\.[0-9]*\.npy\.gz'
filenames = os.listdir('.')
matches = [re.match(re_pattern, filename) for filename in filenames]
matches = [match for match in matches if match]
max_a_match = max(matches, key=lambda x: int(x.groupdict()['a']))
max_a_filename = max_a_match.group()
print(max_a_filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment