如何通过使用简单的编程(例如for循环)将包含对的列表转换为包含元组对的列表?x,y = ...?
我的代码:
def read_numbers():
numbers = ['68,125', '113,69', '65,86', '108,149', '152,53', '78,90']
numbers.split(',')
x,y = tuple numbers
return numbers
需求输出:
[(68,125), (113,69), (65,86), (108,149), (152,53), (78,90)]
def read_numbers():
numbers = ['68,125', '113,69', '65,86', '108,149', '152,53', '78,90']
return [tuple(map(int,pair.split(','))) for pair in numbers]
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句