Python创建一个包含元组的列表

时间:2018-07-20 17:53:43

标签: python python-3.x python-2.7

我试图弄清楚如何在列表中创建元组。我看了几个不同的例子,它们有些不同。

first_names = ['Mark','Ashley','Ron']
points = ['10 points', '10 points', '20 points']

for i in range(len(first_names)):
#     print(first_names[i],points[i])
    scores = first_names[i],points[i]
    print(scores) # tuples

print(scores)的输出1显示:

('Mark', '10 points')
('Ashley', '10 points')
('Ron', '20 points')

最终输出,我试图将其转换为元组列表,例如[(),(),()...()]。每个元组中只有2个元素。

[('Mark', '10 points'),
('Ashley', '10 points'),
('Ron', '20 points')]

尝试:

#     print([list(row) for row in scores]) # try 1 . splits into characters in the word in a list
#     level = map(list,scores) # try 2. splits into characters list within a list 
#     print(list(level))

#     scores = [first_names[i],points[i]] ##?? creates are list of the tuple
#     print(scores)

0 个答案:

没有答案