Answers for "form list of filename get the filename with highest num pythn"

0

form list of filename get the filename with highest num pythn

import re
list_of_files = ["file1","file100","file4","file7"]

def extract_number(f):
    s = re.findall("\d+$",f)
    return (int(s[0]) if s else -1,f)

print(max(list_of_files,key=extract_number))
Posted by: Guest on September-15-2021

Python Answers by Framework

Browse Popular Code Answers by Language