-2

I have list with file paths (as string) from different directories; Im trying to remove duplicate file name (it can be even from different directory). Now I loop through whole list, make a dictionary to remove the duplicates. Is there any other efficient way?

syv
  • 3,528
  • 7
  • 35
  • 50

1 Answers1

-1

try using set()

unique_list = set(list1)

or if you want list returned

unique_list = list(set(list1))
  • I want to compare only the file name not the entire path ... So this might not work. – syv Sep 11 '19 at 19:26
  • @syv then post some examples of these – SuperStew Sep 11 '19 at 19:32
  • I have 3 entries {mypath/xyz.txt, mypath/log/xyz.txt, mypath/abc.txt} I would like to remove second entry as it has same file name "xyz.txt" irrespective of path. Result Im expecting is {mypath/xyz.txt, mypath/abc.txt} – syv Sep 11 '19 at 19:35