![]() |
checking for matches between lists - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: checking for matches between lists (/thread-5835.html) |
checking for matches between lists - henrik0706 - Oct-24-2017 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 oneshow 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! RE: checking for matches between lists - Mekire - Oct-24-2017 Iterate through the elements in given checking if each entry is in the numbers list.Use a for loop and the in operator.
RE: checking for matches between lists - henrik0706 - Oct-24-2017 (Oct-24-2017, 10:46 AM)Mekire Wrote: Iterate through the elements in aah very much appreciated for your quick and honest help! kind regards |