0

I have list with None values. How to sort this list ?

res = sorted(res, key=itemgetter(sort_field), reverse = reverse)

return error:

TypeError: unorderable types: NoneType() < float()
wim
  • 338,267
  • 99
  • 616
  • 750
Bdfy
  • 23,141
  • 55
  • 131
  • 179
  • Where would you expect them to be sorted? – Martijn Pieters Aug 16 '16 at 16:40
  • 2
    You'll need to write a sort key function that handles them appropriately (e.g. turns them into `float('inf')` or `-float('inf')` or something else (depending on where you want them to show up) – mgilson Aug 16 '16 at 16:41

0 Answers0