所以我在这种格式的数组中有数据:
[[x_1,y_1],...,[x_n,y_n]]
我需要这种格式:
[(x_1,y_2),...,(x_n,y_n)]
答案 0 :(得分:3)
对此tuple()
的简单调用就足够了。
>>> testList = [[1, 2], [1, 3]]
>>> [tuple(elem) for elem in testList]
[(1, 2), (1, 3)]
或者,如果您希望使用map
,请执行
>>> map(tuple, testList)
[(1, 2), (1, 3)]