简体   繁体   中英

comparing two lists elements in python

I have 2 lists which consider versions '2.0.0', Im comparing their element and get the list of [True, True, True] meanings, how can i take from list of [True, True, True] meanings, only one meaning True, or if it will be 1 False in that list, how can i get False, globally, i need to override magic methor eq and firstly Im trying to make it simple functionally. I expect to see True if they are equil, and False if something is different in those to lists.

import numpy

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

print(numpy.in1d(a, b))
if numpy.in1d(a, b) == [True, True, True]:
    print('equils')

您正在寻找numpy.all

numpy.all(a == b)

Just use all()

if all(numpy.in1d(a, b)):
    print('equils')

I'm not sure why you would use numpy for that when a simple comparison of tuples will work out of the box

a = ('2','0','0')
b = ('2','0','0')

a == b # --> True


a = ('2','1','0')
b = ('2','0')

a == b # --> False

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM