Python Forum
Sorting list from FTP by Date
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sorting list from FTP by Date
#1
Hi all,

i am parsing a ftp f.retrlines('MLSD', ls.append) which creates me a list that contains Fileinfo like the following

#type=file;size=8889;modify=20200719015840; zzapped +2#-lxt.prg

i isolate the info to 3 different lists with the information filesize,modify and filename
that means list a contains "8889" , listb "20200719015840" and listc "zzapped +2#-lxt.prg"

I want the 3 lists to be sorted simultanusly by filedate and create a new list that contains the files sorted by Date.
Or even better, sort the MLSD list by Date while downloading or afterwards .

f = ftplib.FTP()
	f.port = currentport
	f.connect(ftpaddress)
	f.login()
	f.cwd(remotepath)
	f.retrlines('MLSD', ls.append)
	f.quit()
	
Reply
#2
Use the builtin sorted() function with its key= keyword argument.
Reply
#3
Hi Lastile,
I think you are missing one important detail. You say you have 3 lists. And you want to keep the data together after sorting. This is very difficult.
Instead you should make one list. Each element of this list must also be a list (or tuple or dictionary ...). Each of these nested lists must contain the three elements filesize,modify and filename. So "yourlist[0][0]" would contain the filesize of the first file. And "yourlist[0][2]" the filename etc. Then you can use the sort() or sorted() function with the key= argument as Gribouillis suggested.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  replace nan values by mean group by date.year, date.month wissam1974 5 8,331 Feb-19-2020, 06:25 PM
Last Post: AnkitGupta
  Finding date count from a list of date range in pandas trillerducas72 0 2,720 May-24-2018, 02:30 AM
Last Post: trillerducas72

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020