如何从列表中删除最后 10 个值

问题描述 投票:0回答:0

我有一个 csv 文件列表。必须修剪 python 中的最后 10 个值。下面是我的代码。

s=['SSP_AP_INVOICE_DISTRIBUTIONS_17022023072701.csv','SSP_AP_INVOICE_16022023072701.csv','SSP_HR_ALL_ORGANIZATION_UNITS_18012023043243.CSV']

import datetime as dt

for i in filename:
 date_str = i.split('_')[4]
 x=date_str[:8]
 print(x)

但在我的列表中,很少有 _ 排在第 3、4、5 位。但我可以从第 4 个中删除。我想删除列表中的最后 10 个值,包括 .csv

但我期待输出是这样的:

SSP_AP_INVOICE_DISTRIBUTIONS_17022023 
SSP_AP_INVOICE_16022023 
SSP_HR_ALL_ORGANIZATION_UNITS_18012023
python-3.x csv simpledateformat trim strip
© www.soinside.com 2019 - 2024. All rights reserved.