Instagram
youtube
Facebook
Twitter

Python Program to Compare the Size of Two Lists

A Python Program to Compare the Size of Two Lists?

Code Explanation:

Function Definition:
A function compare_list_size(list1, list2) is defined to compare the lengths of two lists.

Compare Lengths:
Uses len(list1) == len(list2) to check if both lists have the same number of elements.

Return Result:
If sizes are equal, return a message saying both lists are equal in size.
Otherwise, returns a message saying they are not equal.

Create Lists:
Two example lists list1 and list2 are created for comparison.

Function Call and Output:
The function is called and the result is printed based on the size comparison.

 

Program:

def compare_list_size(list1, list2):

    if len(list1) == len(list2):

        return "Both lists are equal in size."

    else:

        return "Lists are not equal in size."

list1 = [1, 2, 3, 4]

list2 = [5, 6, 7, 8]

result = compare_list_size(list1, list2)

print(result)