compare two lists of files, ignoring file extension in one list

后端 未结 4 1492
我在风中等你
我在风中等你 2021-01-20 21:59

I have two lists

list1 = [\'image1.png\', \'image2.png\', \'image3.png\', \'image3.png\']
list2 = [\'image1.pdf\', \'image2.eps\', \'image3.ps\']

4条回答
  •  无人及你
    2021-01-20 22:09

    def filename(name):
        return name.split('.')[0]
    
    list2_filenames = [filename(name) for name in list2]
    found_filenames = [name for name in list1 if filename(name) in list2_filenames] 
    

提交回复
热议问题