which client has 10^5 numbers in his office? Do you do work for an entire telephone company?

Anyway:

print sum(1 for num in nums_dialed if num in client_nums)

That will give you as fast as possible the number.


If you want to do it for multiple clients, using the same nums_dialed list, then you could cache the data on each number first:

nums_dialed_dict = collections.defaultdict(int)
for num in nums_dialed:
    nums_dialed_dict[num] += 1

Then just sum the ones on each client:

sum(nums_dialed_dict[num] for num in this_client_nums)

That would be a lot quicker than iterating over the entire list of numbers again for each client.

Answer from nosklo on Stack Overflow
🌐
Note.nkmk.me
note.nkmk.me › home › python
Count Elements in a List in Python: collections.Counter | note.nkmk.me
May 19, 2023 - Transpose 2D list in Python (swap rows and columns) ... To count unique elements in a list or a tuple, use Counter or set().
🌐
GeeksforGeeks
geeksforgeeks.org › python › find-the-length-of-a-set-in-python
Find the length of a set in Python - GeeksforGeeks
... Sum(1 for _ in a) expression iterates over each element in set "a" and adds 1 for each element. Total sum represents the number of elements in the set which is then printed as length of set.
Published   July 12, 2025
🌐
LabEx
labex.io › tutorials › python-how-to-use-set-to-count-element-frequencies-in-a-python-list-398089
How to use set to count element frequencies in a Python list | LabEx
Python's built-in set() function is a powerful tool that can be leveraged to count the frequencies of elements in a list.
🌐
Medium
medium.com › code-85 › use-sets-to-count-occurrences-in-python-efec802aa3ad
Use Sets to Count Occurrences in Python | by Jonathan Hsu | Code 85 | Medium
December 3, 2020 - I’ve done this in other languages before and had an algorithm which I had ported over to Python. But it dawned on me that there was a better way. Before we jump into the algorithms, here’s a sample input and output to help frame the following solutions. records = [ { "id": 1, "status": "Pass" }, { "id": 2, "status": "Fail" }, { "id": 3, "status": "Pass" }, { "id": 4, "status": "Exempt" } ]counts = countOccurrences(records, "status") """ { "Pass": 2, "Fail": 1, "Exempt": 1 } """
🌐
W3Schools
w3schools.com › python › python_sets.asp
Python Sets
It is also possible to use the set() constructor to make a set. ... thisset = set(("apple", "banana", "cherry")) # note the double round-brackets print(thisset) Try it Yourself » · There are four collection data types in the Python programming language:
🌐
Quora
quora.com › How-do-I-count-the-number-of-sets-including-sets-in-Python
How to count the number of sets including sets in Python - Quora
Answer (1 of 3): Nearly everything in CPython is stored into a single C Language Stack for the following. * All Variables(their types, their indexes and if they are local, function or class method vars). * Lists.() * Dictionaries.(double linked list with indexes and a hash table to search for...
🌐
w3resource
w3resource.com › python-exercises › sets › python-sets-exercise-15.php
Python: Find the length of a set - w3resource
Write a Python program to calculate the number of elements in a set using the len() function. Write a Python program to iterate over a set and count its elements manually without using len().
🌐
Mimo
mimo.org › glossary › python › list-count
Mimo: The coding platform you need to learn Web Development, Python, and more.
The count() function provides the exact number of occurrences of the specific element. You should use count() when working with various data types and data structures: ... Unlike other programming languages like Java or JavaScript, Python's approach is remarkably straightforward.
Find elsewhere
🌐
W3Schools
w3schools.com › python › gloss_python_set_length.asp
Python Get the Length of a Set
Python Overview Python Built-in ... Python Certificate Python Training ... To determine how many items a set has, use the len() method....
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › find the length of the set in python
Find the Length of the Set in Python - Spark By {Examples}
May 31, 2024 - The len() function in Python is used to get the length of the Set. Actually, length gets you the number of elements in the sequence/iterable which includes a python set. The len() function accepts only one parameter i.e iterable and return the ...
🌐
W3Schools
w3schools.com › python › ref_list_count.asp
Python List count() Method
The count() method returns the number of elements with the specified value. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com
🌐
Real Python
realpython.com › python-counter
Python's Counter: The Pythonic Way to Count Objects – Real Python
December 1, 2023 - Here, you first create a multiset using Counter. The keys are equivalent to the set you saw in the example above. The values hold the multiplicity of each element in the set.
🌐
DigitalOcean
digitalocean.com › community › tutorials › find-the-length-of-a-list-in-python
How to find the length of a list in Python | DigitalOcean
July 25, 2025 - Length of 'Python' is 6 characters. Length of 'résumé' is 6 characters. Tuples are ordered, immutable sequences, much like lists. len() behaves identically, counting the total number of elements in the tuple. Sets are unordered collections of unique elements.
🌐
Programiz
programiz.com › python-programming › set
Python Set (With Examples)
Here, we have used for loop to iterate over a set in Python. We can use the len() method to find the number of elements present in a Set.
🌐
Simplilearn
simplilearn.com › home › resources › software development › python count() : how to use count in python
Python Count() Method Explained with Examples
November 13, 2025 - Python's count() function is a built-in function that allows you to count the number of times an element appears in a list or tuple.
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
Educative
educative.io › answers › how-to-get-the-length-of-a-set-in-python
How to get the length of a set in Python
To determine the length of a set in Python, we use the len() function. ... The len() function takes a single mandatory parameter, which is the set data type. The len() function returns the length of the set passed to it.
🌐
Python Engineer
python-engineer.com › posts › count-element-list
How to count the occurrence of an element in a List in Python - Python Engineer
The list data structure in Python has a count() method which returns the count of an element given as a parameter. ... It is important to note that the count() method makes a complete pass over the list every time it is ran, therefore for counting ...
🌐
Appdividend
appdividend.com › python-set-length
How to Get the Length of a Set in Python
July 10, 2025 - To get the length of a Set in Python, you can use the len() function. If your Set contains duplicate elements, it will return the unique count.