長列表包含一些要排序的元素。按組件列表排序字符串
實際上每個元素都有4個內容:姓名,進/出,地區和日期&時間,加入'〜'。 ('〜'可以更改。)我想將列表重新組織成排序順序。
a_list = ["Chris~Check-in~Zoom A~11/13/2013 05:20",
"Chris~Check-in~Zoom G~11/15/2013 14:09",
"Frank E~Check-in~Zoom K~11/11/2013 08:48",
"Frank E~Check-in~Zoom K~11/15/2013 21:32",
"Kala Lu S~Check-in~Zoom N~11/13/2013 07:20",
"Milly Emily~Check-in~Zoom G~11/13/2013 01:08",
"Milly Emily~Check-in~Zoom E~11/16/2013 14:39",
"Milly Amy~Check-in~Zoom G~11/10/2013 20:14",
"Milly Amy~Check-in~Zoom A~11/16/2013 08:55",
"Milly Amy~Check-in~Zoom O~11/14/2013 21:57",
"Milly Amy~Check-in~Zoom A~11/15/2013 10:45",
"Nago Iko~Check-in~Zoom K~11/16/2013 20:42",
"Nago Iko~Check-in~Zoom K~11/14/2013 10:46",
"Liz D~Check-in~Zoom N~11/15/2013 01:46",
"Liz D~Check-in~Zoom A~11/12/2013 09:54",
"Liz D~Check-in~Zoom G~11/16/2013 13:15",
"Chris~Check-out~Zoom A~11/13/2013 13:42",
"Chris~Check-out~Zoom G~11/11/2013 14:21",
"Chris~Check-out~Zoom G~11/16/2013 09:41",
"Frank E~Check-out~Zoom K~11/14/2013 03:02",
"House P~Check-out~Zoom K~11/10/2013 11:17",
"Kala Lu S~Check-out~Zoom G~11/11/2013 23:27",
"Kala Lu S~Check-out~Zoom N~11/14/2013 11:17"]
它可以導入到MS Excel和排序,但我想知道如果Python可以做的工作。
是否有可能通過在列表中的順序對它們進行排序:1名,2日&時間3區4進/出像:
new_list = ["Chris~Check-out~Zoom G~11/08/2014 14:21",
"Chris~Check-in~Zoom A~11/10/2014 05:20",
"Chris~Check-out~Zoom A~11/10/2014 13:42",
"Chris~Check-in~Zoom G~11/12/2014 14:09",
"Chris~Check-out~Zoom G~11/13/2014 09:41",
"Frank E~Check-in~Zoom K~11/08/2014 08:48",
"Frank E~Check-out~Zoom K~11/11/2014 03:02",
"Frank E~Check-in~Zoom K~11/12/2014 21:32",
...
...]
感謝。
我覺得應該是'X [0],x [3],x [2],x [1]'如果你想尊重OP的排序順序。 – Thibaut
@Thibaut是的,我剛剛編輯它。謝謝! – parchment
謝謝,羊皮紙。這真太了不起了。 –