簡體   English   中英

Python:'list'對象不能解釋為整數

[英]Python:'list' object cannot be interpreted as an integer

points 1 =[1219.5537056928035, [1318.8861439312564, 1214.6746106337268,
           1110.4630773361973, 1006.2515440386678, 902.0400107411383]]

對於上面的列表,我想創建有序對,將點 1[0] 視為 X 軸,將點 1[1] 視為 Y 軸。 例子:

[(1219.553,1318.88),(1219.553,1214.674), (1219.553,1110.465)...................   

list(zip(itertools.repeat(points1[0],points1[1])))

我正在嘗試使用 zip,但出現錯誤:

'list' object cannot be interpreted as an integer 

您可以在此處使用itertools.product

list(itertools.product([points1[0]],points1[1]))

[(1219.5537056928035, 1318.8861439312564),
 (1219.5537056928035, 1214.6746106337268),
 (1219.5537056928035, 1110.4630773361973),
 (1219.5537056928035, 1006.2515440386678),
 (1219.5537056928035, 902.0400107411383)]

對於你得到的錯誤。 itertools.repeat的簽名是

itertools.repeat(object[, times])

times以整數作為參數的地方,你給了它一個列表。

points1 =[1219.5537056928035, [1318.8861439312564, 1214.6746106337268,
           1110.4630773361973, 1006.2515440386678, 902.0400107411383]]

x = points1[0]
ys= points1[1]

print([ (x,y) for y in ys])

輸出:

[
 (1219.5537056928035, 1318.8861439312564), 
 (1219.5537056928035, 1214.6746106337268),
 (1219.5537056928035, 1110.4630773361973),
 (1219.5537056928035, 1006.2515440386678),
 (1219.5537056928035, 902.0400107411383)
]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM