Ordering objects is one thing that is changing as we will move to Python3

Python 2.6 gives interesting results

a=[1,'23',('a','b'),False,[[]],[],'bc',['ab','34'],45,'0',{},True]
>>> sorted(a)
[False, 1, True, 45, {}, [], [[]], ['ab', '34'], '0', '23', 'bc', ('a', 'b')]
>>> print True==1
True
>>> print False==0
True
>>> print False==''
False

Python3 has sense to give up but still gives interesting results

Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> a=[1,'23',('a','b'),False,[[]],[],'bc',['ab','34'],45,'0',{},True]
>>> sorted(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unorderable types: str() < int()
>>> True==1
True
>>> True<2
True
>>> True>0.5
True
>>> True+2
3
>>>

It has never made much sense to sort mixed type lists. So it's nice to see that Python3 put a stop to it ...

mixed_list = [3, 2, 'a', (5, 2,), 'd', 'c']

print(sorted(mixed_list))

"""my result -->
Python2
[2, 3, 'a', 'c', 'd', (5, 2)]
Python3
TypeError: unorderable types: str() < int()
"""
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.