How to compare two list values
Compare two list values
list1 = ['abc', 123]
list2 = ['xyz', 789]
list3 = ['abc', 123]
print list1 < list2
print list2 < list3
print list2 > list3 and list1 == list3
# ww w . ja v a2 s.c o m
L1 = [1, ('a', 3)]
L2 = [1, ('a', 2)]
print L1 < L2, L1 == L2, L1 > L2 # less,equal,greater: tuple of results
Compare the nested list objects
print [2, [1, 4]] < [2, [1, 5]]
The code above generates the following result.
Use cmp() to compare lists
list1, list2 = [123, 'xyz'], [456, 'abc']
print cmp(list1, list2)
print cmp(list2, list1)
list3 = list2 + [789]# from ww w . j a v a2s.co m
print list3
print cmp(list2, list3)