Write a Python function that takes in two lists and calculates whether they are permutations of each other. The lists can contain both integers and strings. We define a permutation as follows:
the lists have the same number of elements
list elements appear the same number of times in both lists
If the lists are not permutations of each other, the function returns False.
If they are permutations of each other, the function returns a tuple consisting
of the following elements:
the element occuring the most times
how many times that element occurs
the type of the element that occurs the most times
If both lists are empty return the tuple (None, None, None). If more than one
element occurs the most number of times, you can return any of them.
"""
def is_list_permutation(L1, L2):
'''
L1 and L2: lists containing integers and strings
Returns False if L1 and L2 are not permutations of each other.
If they are permutations of each other, returns a
tuple of 3 items in this order:
the element occurring most, how many times it occurs, and its type
'''
if helper_permutation(L1,L2) == False:
return False
elif not L1:
return (None, None, None)
else:
most = max(set(L1), key=L1.count)
num = L1.count(most)
typ = type(most)
return (most, num, typ)
def helper_permutation(L1,L2):
if len(L1) != len(L2): # UNEQUAL LENGTH MEANS PERMUTATIONS OF EACH OTHER IS NOT POSSIBLE
return False;
for i in range(0, len(L1)):
if L1.count(L1[i]) != L2.count(L1[i]):
return False
If the answers is incorrect or not given, you can answer the above question in the comment box. If the answers is incorrect or not given, you can answer the above question in the comment box.