How can I compare two ordered lists in python?

前端 未结 3 901
伪装坚强ぢ
伪装坚强ぢ 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:06

    If you want to just check if they are identical or not, a == b should give you true / false with ordering taken into account.

    In case you want to compare elements, you can use numpy for comparison

    c = (numpy.array(a) == numpy.array(b))

    Here, c will contain an array with 3 elements all of which are true (for your example). In the event elements of a and b don't match, then the corresponding elements in c will be false.

提交回复
热议问题