Menu Close

Compare two List in python

Write a program to compare two list and display the comparison result

Input:

  1. The Size of First List
  2. The Size of Second List
  3. First List elements
  4. Second List elements

Output:

  1. Output of comparison of List A with List B
  2. Output of comparison of List B with List A

Refer sample input and output for formatting specification.

def cmp(a,b):
  return (a>b)-(a<b)
N1=int(input("Enter the size of First list: "))
N2=int(input("Enter the size of Second list: "))
l1=[]
l2=[]
print('First List Elements: ')
for i in range(N1):
  l1.append(int(input('')))
print('Second List Elements: ')
for i in range(N2):
  l2.append(int(input('')))
print(cmp(l1,l2))
print(cmp(l2,l1))

cmp function: This function returns 1, if first list is “greater” than second list,
-1 if first list is smaller than the second list else it returns 0 if both the lists are equal.
As it returns boolean value True-1 or False-0, hence 1-0=1 and 0-1=-1
Various Inputs are given here ?


Input_1:
Enter the size of First list: 3
Enter the size of Second list: 3
First List Elements:
3
6
7
Second List Elements:
2
2
3
Output:
1
-1


Input_2:
Enter the size of First list: 2
Enter the size of Second list: 2
First List Elements:
67
99
Second List Elements:
69
91
Output:
-1
1


Morae!Q!

->Insert and Extend in list python
->Print Odd Numbers in range
->Compare List in python
->Find whether the largest element in the array is at least twice as much as every other number in the array.
->Find minimum cost to reach the top of the floor
->Word Count in Python
->Lower case to upper case in python
->Display Time in python
->Sum of Odd And Even in Python
->Surface Area of Walls
->Find the sum of squares of individual digits
->Print the given series – 1 1 2 6 24
->Minimum number of steps required to reach destination.
->Seconds to Days Hours Minutes
->Program to remove add “Hyphen” character in the entered string
->Remove the nth Index Character from a Non-Empty String
->Relational operator Question
->Check whether all the given numbers lies in range of x and y.
->Find the Armstrong numbers between the given range.