1
    Python 3.6.7

    >>> a = [('a',1), ('b', 2), ('c',3), ('d',4)]
    >>> b = [('b',2), ('c', 3), ('a',1)]
    >>>
    >>>
    >>> a.sort() == b.sort()
    True

    >>> a = [('a',1), ('b', 2), ('c',3), ('d',4)]
    >>> b = [('b',2), ('c', 3), ('a',1)]
    >>>
    >>> sorted(a) == sorted(b)
    False
    >>>

I was expecting sort() to return false. What is the difference between sort and sorted causing this behaviour.

Anand
  • 145
  • 1
  • 3
  • 10

0 Answers0