How can I compare two ordered lists in python?

前端 未结 3 900
伪装坚强ぢ
伪装坚强ぢ 2020-12-05 03:24

If I have one long list: myList = [0,2,1,0,2,1] that I split into two lists:

a = [0,2,1]
b = [0,2,1]

how can I compare these t

3条回答
  •  生来不讨喜
    2020-12-05 04:05

    Just use the classic == operator:

    >>> [0,1,2] == [0,1,2]
    True
    >>> [0,1,2] == [0,2,1]
    False
    >>> [0,1] == [0,1,2]
    False
    

    Lists are equal if elements at the same index are equal. Ordering is taken into account then.

提交回复
热议问题