Created
October 29, 2016 16:21
-
-
Save sushain97/f7fb85b3fb4f679fec59208b0b740ee5 to your computer and use it in GitHub Desktop.
This file contains 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 sys | |
import os | |
import collections | |
import itertools | |
import pprint | |
filenames = list(os.listdir(sys.argv[1])) | |
# filenames = list(filter(lambda x: any(map(lambda y: x.startswith('%s@' % y), andrew_ids)), filenames)) | |
grouped_filenames = collections.defaultdict(list) | |
for filename in filenames: | |
grouped_filenames[filename.split('@')[0]].append(filename) | |
# pprint.pprint(grouped_files) | |
final_submission_nums = dict(map(lambda x: (x[0], max(map(lambda y: int(y.split('_')[1]), x[1]))), grouped_filenames.items())) | |
final_submissions = dict(map(lambda x: (x[0], list(filter(lambda y: int(y.split('_')[1]) == final_submission_nums[x[0]], x[1]))), grouped_filenames.items())) | |
final_filenames = list(itertools.chain(*final_submissions.values())) | |
for filename in filenames: | |
if filename not in final_filenames: | |
os.remove(os.path.join(sys.argv[1], filename)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment