我的代码一直工作正常,突然出现了以下错误:
unorderable types: str() > float()
我通过API提取订单簿,然后希望获得金额大于1的所有订单。你知道吗
filtermaxxamount = (x for x in dic if x['max_amount'] > 1)
这似乎是一个“生成器”类。
然后我想从filtermaxxamount
中提取最高价格:
highestprice = ((max((x for x in filtermaxxamount if x['min_amount'] < 1),
key=lambda x:x['price']))['price'])
在这之后,我得到了上面提到的错误。 以前一切都很顺利,我也没有任何问题。API没有改变,我在网站上查过。你知道吗
我犯了什么错误? 有什么问题?它一定是一本字典而不是一个生成器,对吗?你知道吗
您似乎已从Python2切换到Python3。你知道吗
在Python 2中,所有的
type
都可以排序:在Python 3中,情况不再是这样:
见Why is the order of types in Python 2 fixed, and an unorderable TypeError in Python 3?
要解决您的问题:(除了dupe建议之外,我还回答了原因)
将元素筛选为具有浮点值和非字符串的元素:
输出:
相关问题 更多 >
编程相关推荐