Python Forum

Full Version: checking for matches between lists
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey guys

so here's the problem
I have 2 lists:
numbers = [1,2,3,4,5,6,7,8,9]
given = [1,1,2]
how do i find the amount of elements in the given-list that match the numbers-list?

len(set(numbers) & set(given)) gives me 2, because it doesn't count the multiple ones
how do i also count the multiple matches, giving me 3?

(the real question is with letters but the numbers are to simplify things)


thank you!
Iterate through the elements in given checking if each entry is in the numbers list.
Use a for loop and the in operator.
(Oct-24-2017, 10:46 AM)Mekire Wrote: [ -> ]Iterate through the elements in given checking if each entry is in the numbers list.
Use a for loop and the in operator.

aah very much appreciated for your quick and honest help!

kind regards