首页 > 解决方案 > 'list' 和 'int' 的实例之间不支持 '>='

问题描述

我正在尝试使用条件从 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'

标签: pythonpython-3.x

解决方案


也许:

#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

推荐阅读