Python Forum
Sort Function: <' not supported between instances of 'float' and 'tuple' - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Sort Function: <' not supported between instances of 'float' and 'tuple' (/thread-33500.html)



Sort Function: <' not supported between instances of 'float' and 'tuple' - quest - Apr-30-2021

Hello I have this list:

Output:
[((7.2, <__main__.bit object at 0x7f341d8b8700>), <__main__.port object at 0x7f344082cd00>), ((5.5, <__main__.bit object at 0x7f341d8b8790>), <__main__.port object at 0x7f34407aa190>)]
ANd I want to sort it with this code:

nextlist=[(next(ip),ip) for ip in ports]
        while len(nextlist)>0:
            nextlist.sort() 
But I have this error:

nextlist.sort()

TypeError: '<' not supported between instances of 'float' and 'tuple'

HOw to solve it


RE: Sort Function: <' not supported between instances of 'float' and 'tuple' - Larz60+ - Apr-30-2021

  • Fix indentation
  • Show complete unaltered error traceback (wrapped with bbcode error tags)
  • Show contents of nextlist (after line 1 has executed)



RE: Sort Function: <' not supported between instances of 'float' and 'tuple' - quest - Apr-30-2021

(Apr-30-2021, 12:41 PM)Larz60+ Wrote:
  • Fix indentation
  • Show complete unaltered error traceback (wrapped with bbcode error tags)
  • Show contents of nextlist (after line 1 has executed)

it is already working now. Just the data was coming differently from the other function. I corrected the other function so now this structure is working. Btw, I already showed the contents of nextlist at the top!!