21.将列表["to”,"take”,”the”,”time”,"to”,"smell”,"the”,"roses”]和列表["花花”,”时间”,”时间”,”闻闻”,”身边的”,“玫瑰”]连接,相邻两个单词之间插入指定字符*,注意:相关逗号、引号等的中英文输入法保持一致
时间: 2024-05-08 13:15:18 浏览: 39
learning-to-smell-starter-kit
代码如下:
```python
list1 = ["to", "take", "the", "time", "to", "smell", "the", "roses"]
list2 = ["花花", "时间", "时间", "闻闻", "身边的", "玫瑰"]
result = []
for i in range(len(list1)):
result.append(list1[i])
result.append("*")
result.append(list2[i])
result.pop() # 删除最后一个多余的星号
print(result)
```
输出结果为:
```
['to', '*', '花花', 'take', '*', '时间', 'the', '*', '时间', 'time', '*', '闻闻', 'to', '*', '身边的', 'smell', '*', '玫瑰', 'the']
```
阅读全文