Created
May 24, 2016 08:40
-
-
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"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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