【发布时间】:2014-01-03 17:45:51
【问题描述】:
我有一个类似的问题here,但这是一个不同的问题。我有两个清单。 list0 是字符串列表,list1 是由整数组成的列表列表。
# In this example are 8 strings
list0 = ["Test", "Test2", "More text", "Test123", "ttt", "abc", "okokok", "Hello"]
list1 = [ [0, 1], [2], [3], [4,5,6], [7] ...... ]
# therefore 8 ints, 0 - 7; it always starts with 0.
list0 中的字符串数量与 list1 中的整数数量完全相同。
我想遍历 list1 ([0,1], [2], ...) 的项目,并根据来自 list1 的项目的 int 数连接来自 list0 的字符串。所以new_list[0]+new_list[1] 应该连接,2 和 3 不应该连接,而不是 4+5+6 应该连接等等......我不知道如何在一个 for 循环中做到这一点,因为一个项目中的整数数量可以各不相同。所以我正在寻找的是一个新的串联列表,应该如下所示:
# 0 and 1 2 3 4 5 6 7
new_list = ["TestTest", "More text", "Test123", "tttabcokokok", "Hello"]
我该怎么做?
【问题讨论】:
标签: python