'list'和'int'的实例之间不支持'> ='

时间:2018-12-31 00:41:05

标签: python python-3.x

我正在尝试使用条件从txt,文件列表中提取3个切片,我已经尝试使用过滤器和列表理解来进行切片,但是它们都给出相同的错误。是什么导致此错误?

当我尝试运行它时,会导致此错误:

Traceback (most recent call last):
File "teste5.py", line 25, in <module>  
vetor_xB = vetor_x[vetor_x >= 400 : X <= 500]   
TypeError:'>=' not supported between instances of 'list' and 'int'

1 个答案:

答案 0 :(得分:0)

也许:

#Conditions
B = 0
G = 0
R = 0
for i in range(0,len(vetor_x):
    if vetor_x[i]<=500:
       vetor_xB[B] = vetor_x[i] 
       vetor_yB[B] = vetor_y[i]
       B += 1
    elif vetor_x[i]<=600:
       vetor_xG[G] = vetor_x[i]
       vetor_yG[G] = vetor_v[i]
       G += 1
    elif vetor_x[i] <= 700:
       vetor_xR[R] = vetor_x[i]
       vetor_yR[R] = vetor_y[i]
       R += 1