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
  • 302,178
  • 90
  • 548
  • 690
Bdfy
  • 21,109
  • 53
  • 126
  • 178
  • 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