Here is how you can use a nested for
-loop with formmatted strings:
list1 = ["ilovepython","ilovec#"]
list2 = ["love","python"]
for i in list1: # For every string in list11
print(f'in "{i}":') # Print the string
for j in list2: # For every string in list2
num = i.count(j) # Store the number of occurrences of the second string in the first string
print(f'number of "{j}" = {num}') @ Print the number of ocurrences with a formatted string
Output:
in "ilovepython":
number of "love" = 1
number of "python" = 1
in "ilovec#":
number of "love" = 1
number of "python" = 0
2
solved Compare occurrences between str in two lists [closed]