小编Ald*_*Tan的帖子

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

我试图将列表值从一个列表插入另一个列表,但按特定顺序,其中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 …
Run Code Online (Sandbox Code Playgroud)

python list

6
推荐指数
1
解决办法
727
查看次数

标签 统计

list ×1

python ×1