![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
Comparing two tuples gives expected result
print (1, 2) < (1, 3) # True, makes sense print [1, 2] < [1, 3] # True print [1, 2] < (1, 3) # True, looks okay print (1, 2) < [1, 3] # False, oops!
__________________
I looked it up on the Intergnats! |
|
|
|
|
|
#2 | |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Quote:
>>> [1, 2] < (0, 1) True >>> [1, 2] < (0,) True |
|
|
|
|
|
|
#3 | |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
Quote:
Moral, don't compare tuples (pears) with lists (apples)!
__________________
I looked it up on the Intergnats! |
|
|
|
|
|
|
#4 |
|
Programming Guru
![]() |
Unless you convert either or with list()/tuple() >.>
^_^ |
|
|
|
|
|
#5 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
I will stop to be silly after this:
[PHP]# a mixed object list list1 = [2, 1.99, [1, 2], (1, 2), {'c': 1, 'b': 2}, "bush"] # sort/compare order seems to be numerics (float or integer), dictionary, list, string, tuple print sorted(list1) # [1.99, 2, {'c': 1, 'b': 2}, [1, 2], 'bush', (1, 2)][/PHP]
__________________
I looked it up on the Intergnats! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|