我想将两个字符串作为单个元素附加到 Python 列表中。这是我的问题的简化示例:
lowerCase = [['a', 'b', 'c', 'd', 'e']]
newList = []
# Append two pieces of data as a single element
i = 1;
for letter in lowerCase[0]:
[newList.append(letter), newList.append(i)]
i += 1
print newList
print len(newList)
我得到什么:
['a', 1, 'b', 2, 'c', 3, 'd', 4, 'e', 5]
10
我想要的是:
[['a', 1], ['b', 2], ['c', 3], ['d', 4], ['e', 5]]
5