Py学习  »  Python

Python:“list”对象不能解释为整数

indu • 6 年前 • 2333 次点击  
points 1 =[1219.5537056928035, [1318.8861439312564, 1214.6746106337268,
           1110.4630773361973, 1006.2515440386678, 902.0400107411383]]

例子:

[(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 
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/56520
文章 [ 2 ]  |  最新文章 6 年前
Ch3steR
Reply   •   1 楼
Ch3steR    6 年前

你可以用 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 以整数作为参数,然后给它一个列表。

Mr.Baqaisooo
Reply   •   2 楼
Mr.Baqaisooo    6 年前
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)
]