0

まず、簡単な質問で申し訳ありません。私はリストを持っています(ほんの一例)

points = [[663963.7405329756, 6178165.692240637],
 [664101.4213951868, 6177971.251818423],
 [664099.7474887948, 6177963.323432223],
 [664041.432877932, 6177903.295650704],
 [664031.8017317944, 6177895.797176996],
 [663963.7405329756, 6178165.692240637]]

次の形式に変換する必要があります

points = [(663963.7405329756, 6178165.692240637),
 (664101.4213951868, 6177971.251818423),
 (664099.7474887948, 6177963.323432223),
 (664041.432877932, 6177903.295650704),
 (664031.8017317944, 6177895.797176996),
 (663963.7405329756, 6178165.692240637)]

shapely modulePolygonを使用してオブジェクトを作成するため。私はいくつかのループを書きましたが、実際にはエレガントではなく、時間がかかりました。最初のリストを 2 番目のリストに変換する最良の方法を知っていますか?

ありがとう

4

4 に答える 4

5
converted = map(tuple, points) # Python 2
converted = list(map(tuple, points)) # or BlackBear's answer for Python 3
converted = [tuple(x) for x in points] # another variation of the same
于 2013-01-08T21:12:15.650 に答える
2
converted = [tuple(l) for l in points]

@BlackBearによって提供されるソリューションと比較すると、これは任意のサイズのサブリストに対して機能します。

于 2013-01-08T21:16:28.827 に答える
2
converted = [(a,b) for a,b in points]
于 2013-01-08T21:11:02.747 に答える
1
points = [tuple(x) for x in points]
于 2013-01-08T21:14:30.633 に答える