How could I check if an element of a list is in a second list, but if the element of the first list has another same value (appears multiple times), the second list needs to have another too (needs to have multiple instances too).
I will show my code and output to demonstrate what I want it to be.
Input:
List_1 = [1, 2, 2]
List_2 = [1, 2, 2, 3, 4]
print("First list is", List_1)
print("Second list is", List_2)
res = all(ele in List_2 for ele in List_1)
print(f"Output: {res}")
Output:
First list is [1, 2, 2]
Second list is [1, 2, 2, 3, 4]
Output: True
As you can see, if element of a first list has another same value, second list needs to have it too.
But if second list doesn't have another value, I want it to be false.
This is an example.
Input:
List_1 = [1, 2]
List_2 = [1, 2, 2, 3, 4]
print("First list is", List_1)
print("Second list is", List_2)
res = all(ele in List_2 for ele in List_1)
print(f"Output: {res}")
My desired output is:
First list is [1, 2]
Second list is [1, 2, 2, 3, 4]
Output: False
This is the output that I want. How could I fix my code?