我试图弄清楚如何在列表中创建元组。我看了几个不同的例子,它们有些不同。
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)