Python :'list' 对象无法解释为整数

标签 python python-3.x list zip python-itertools

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 将整数作为参数,并给它一个列表。

关于Python :'list' 对象无法解释为整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60774040/

相关文章:

Python - 如何使用 bs4 抓取 javascript 代码)?

python - 如何快速制作这种相等数组(在 numpy 中)?

python - python 专家的问题 : code doesn't work when called with generators

Python Beautiful Soup 4 使用 .select() 获取元素的子元素

python - 为什么 PyQt4 DialogBox OpenFileName 在 Linux 下卡住直到其他线程完成

java - 将 ArrayList 转换为 Collections.synchronizedList

python - Wireshark 未检测到 TLS 连接

python - 导入错误: No module named cassandra in Azure Machine Learning Studio

Python 排列作为列表理解

java - 如何在使用自定义方式保存数据 RecyclerView 时制作列表更改动画