我是蟒蛇的新秀 从这段代码
b=[]
a=[]
c=[1-1-1904 01:00:00,000000, 1-1-1905 02:00:00,000000, 1-1-1906 03:00:00,000000]
#with open('nt.txt') as csvfile:
# data=csv.reader(csvfile,delimiter=('\t'))
index=0
for line in data:
if (index >= 0 and index <= 2):
b.append(line[1])
index += 1
else:break
我得到如下
3
['1-1-1904 01:00:00,000000', '1-1-1904 01:00:01,000000', '1-1-1904 01:00:02,000000']
我想分割日期和时间戳,并将它们分别放入新列表中。我添加了一个测试,因为你可以运行 我怎么能这样做?
答案 0 :(得分:0)
如果您的输入是:
A = ['1-1-1904 01:00:00,000000', '1-1-1904 01:00:01,000000', '1-1-1904 01:00:02,000000']
并使用以下代码:
list_1 = []
list_2 = []
list_3 = []
for item in A:
temp = item.split(',')
list_3.append(temp[-1])
temp1 = temp[0].split(" ")
list_1.append(temp1[0])
list_2.append(temp1[1])
print list_1
print list_2
print list_3
你会得到这个作为输出:
list_1 = ['1-1-1904', '1-1-1904', '1-1-1904']
list_2 = ['01:00:00', '01:00:01', '01:00:02']
list_3 = ['000000', '000000', '000000']
这是你在找什么?