form list of filename get the filename with highest num pythn

Solutions on MaxInterview for form list of filename get the filename with highest num pythn by the best coders in the world

showing results for - "form list of filename get the filename with highest num pythn"
Monica
26 Sep 2018
1import re
2list_of_files = ["file1","file100","file4","file7"]
3
4def extract_number(f):
5    s = re.findall("\d+$",f)
6    return (int(s[0]) if s else -1,f)
7
8print(max(list_of_files,key=extract_number))
9
similar questions