Вы, кажется, перешли с Python 2 на Python 3.
В Python 2 все type
с были заказаны:
print(sorted( [1,"2",3,"None"]`))
# Output: [1,3,'2','None']
В Python 3 это уже не так:
print(sorted( [1,"2",3,"None"]`))
# TypeError: '<' not supported between instances of 'str' and 'int'
# workaround for sorting: use an explicit key function
print(sorted( [1,"2",3,"None"], key=lambda x: 999999999999 if isinstance(x,str) else x))
См. Почему исправлен порядок типов в Python 2 и неупорядоченная ошибка TypeError в Python 3?
Чтобы исправить вашу проблему: (и причину, по которой я ответил, в дополнение к предложению обмана)
Отфильтруйте элементы к тем, которые имеют значение с плавающей запятой и не являются строкой:
l = [ {'max_amount' : 33.0}, {'max_amount' : -33.0}, {'max_amount' : 12.6},
{'max_amount' : "None"}, {'max_amount' : "34"}]
try:
# only look at those that are floats (seperated for clarity)
filter_float = (x for x in l if isinstance(x['max_amount'],float))
# from those filter the > 1 ones
filtermaxxamount = (x for x in filter_float if x['max_amount'] > 1)
# creates an error:
# filtermaxxamount = (x for x in l if x['max_amount'] > 1)
print(*filtermaxxamount)
except TypeError as e:
print(e) # never reached unless you uncomment # filtermaxxamount = (x for x in l ...
Выход:
{'max_amount': 33.0} {'max_amount': 12.6}