【发布时间】:2013-07-05 06:09:10
【问题描述】:
我想将两个字符串作为单个元素附加到 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
【问题讨论】:
标签: list python-2.7 append element