我该如何格式化两个列表?

时间:2017-05-05 16:10:44

标签: python-2.7 format

我有一个列表,如:

y=['1997,05,22', '1997,05,21', '1997,05,20', '1997,05,19', '1997,05,16', '1997,05,15'........]

我尝试使用.format更改列表的fotmat,如:

[new Date(1997,05,22),new Date(1997,05,21),new Date(1997,05,20),...]

首先我尝试

y2 = []
for i in y:
z = 'new Date({0},{1},{2})'.format(*i)
y2.append(z)

以获取[new Date(1997,05,22),...]之类的列表,但输出如下:

['new Date(1,9,9)', 'new Date(1,9,9)', 'new Date(1,9,9)', 'new Date(1,9,9)', 'new Date(1,9,9)', 'new Date(1,9,9)']

任何想法? Thansk!

0 个答案:

没有答案