(Jul-12-2020, 10:11 AM)DeaD_EyE Wrote: Iterate over the open file, then you get line by line.
Instead of regex you could usestr.rsplit()
orstr.rpartition()
.
pdf_files = set() # https://docs.python.org/3/library/stdtypes.html#set with open(file) as fd: for line in file: url, last = line.strip().rsplit("/", 1) # https://docs.python.org/3/library/stdtypes.html#str.rsplit print(last) # then check if last.endswith(".pdf") # if true, add it to the set # Now sort pdf_files with sorted # https://docs.python.org/3/library/functions.html#sorted sorted_pdfs = sorted(pdf_files)PS: If in one line is more than one address, you could split them with thesplit()
method.
I am using linux so where should I put the path of the file in the script
I tried it like this
a= "/home/file.txt"
pdf_files = set(a)
but it didn't work .. also I need the result without brackets only the name of one file in each line
thank you