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
🌐
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
🌐
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().
🌐
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 } """
🌐
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.
🌐
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.
🌐
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...
🌐
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:
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....
🌐
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
🌐
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 ...
🌐
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.
🌐
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.
🌐
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.
🌐
Hyperskill
hyperskill.org › university › python › python-count-function
Python count() Function
December 25, 2025 - As for the count() method with lists it calculates how times a specific element is present within the list and gives you that count. This feature comes in handy when you need to track occurrences of words in sentences or determine the frequency of specific numbers in lists of integers.
🌐
Reddit
reddit.com › r/learnpython › confused on using a set to count duplicates
r/learnpython on Reddit: confused on using a set to count duplicates
August 12, 2024 -

If a set doesn't contain duplicates, then how does this work? I'm missing some key details of a set.

def count_duplicates(i):
    unique_elements = set(i)
    duplicates = []
    for element in unique_elements:
        if i.count(element) > 1:
            duplicates.append((element, i.count(element)))
    return i, unique_elements, duplicates

my_str = 'fuzz'
a,b,c = count_duplicates(my_str)
print(a)
print(b)
print(c)

[OUTPUT]
fuzz # initial string
{'f', 'u', 'z'} # set from string
[('z', 2)] # dict of duplicates with count
🌐
Real Python
realpython.com › python-sets
Sets in Python – Real Python
May 5, 2025 - To find out how many elements a set contains, simply call the len() function with your set as an argument: ... Because sets don’t allow duplicates, you’ll always get the count of distinct items, making len() a quick way to verify the uniqueness ...
🌐
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.