在Python中以特定顺序将列表值从列表插入到另一个列表中

Ald*_*Tan 6 python list

我试图将列表值从一个列表插入另一个列表,但按特定顺序,其中date [0]输入文本[1],日期[1]输入文本[3],依此类推.

dates=['21/11/2044', '31/12/2018', '23/9/3000', '25/12/2007']

text=['What are dates? ', ', is an example.\n', ', is another format as
well.\n', ', also exists, but is a bit ludicrous\n', ', are examples but more commonly used']
Run Code Online (Sandbox Code Playgroud)

我试过这个方法:

for j in range(len(text)):
  for i in range(len(dates)):
   text.insert(int((j*2)+1), dates[i])
Run Code Online (Sandbox Code Playgroud)

这是结果,这是不正确的:

['What are dates? ', '25/12/2007', '23/9/3000', '25/12/2007', '23/9/3000',
'25/12/2007', '23/9/3000', '25/12/2007', '23/9/3000', '25/12/2007',
'23/9/3000', '31/12/2018', '21/11/2044', '31/12/2018', '21/11/2044',
'31/12/2018', '21/11/2044', '31/12/2018', '21/11/2044', '31/12/2018',
'21/11/2044', ', is an example.\n', ', is another format as well.\n', ',
also exists, but is a bit ludicrous\n', ', are examples but more commonly used']
Run Code Online (Sandbox Code Playgroud)

我试图找回一个如下所示的列表:

['What are dates? ','21/11/2044', 'is an example.\n','31/12/2018', ', is
another format as well.\n','23/9/3000', ', also exists, but is a bit
ludicrous\n', '25/12/2007',', are examples but more commonly used']
Run Code Online (Sandbox Code Playgroud)

有没有办法按我想要的方式将日期[i]插入文本[2*j + 1]?我是否应该使用for循环,或者是否有其他方式而不在日期中列出所有内容?

小智 0

您可以使用:

result = [ ]
for x in enumerate(dates, text):
   result.append(dates[x]).append(text[x])
Run Code Online (Sandbox Code Playgroud)