I have four elements to compare with
A= [1,2,3,4]
B=[1,2]
C= [3,5,6]
D= [2, 4, 5, 6,7]
How do I compare which one has the greatest len?
您可以使用max
键。
max(a,b,c,d,key=len)
You can use the len function, eg
len(A)
gives
4
So it would be something like:
len_a = len(A)
len_b = len(B)
len_c = len(C)
len_d = len(D)
max_length = max([len_a, len_b, len_c, len_d])
if len_a == max_length:
print 'A'
if len_b == max_length:
print 'B'
if len_c == max_length:
print 'C'
if len_c == max_length:
print 'D'
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.