def get_key(fname):
    return int(re.findall('\\d+', fname)[0])
d = defaultdict(list)
for f in files:
    d[get_key(f)].append(f)
out = [d[k] for k in sorted(d.keys())]
print(out)
Sorting files in a list