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
🌐
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....
🌐
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 } """
🌐
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.
🌐
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().
🌐
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...
🌐
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().
🌐
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 ...
Find elsewhere
🌐
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
🌐
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.
🌐
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
🌐
Programiz
programiz.com › python-programming › methods › list › count
Python List count()
Created with over a decade of experience. ... Created with over a decade of experience and thousands of feedback. ... Try Programiz PRO! ... Become a certified Python programmer. Try Programiz PRO! ... The count() method returns the number of times the specified element appears in the list.
🌐
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
🌐
Better Programming
betterprogramming.pub › count-items-in-python-with-the-help-of-counter-objects-c08d8d486e45
Count Items in Python With the Help of Counter Objects | by Yong ...
August 7, 2020 - If we want to count the occurrences of all the elements, we’ll have to iterate them, as shown in the following code snippet: ... Advice for programmers. ... Work at the nexus of biomedicine, data science & mobile dev. Author of Python How-to by Manning (https://www.manning.com/books/pyth...
🌐
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.
🌐
Stack Overflow
stackoverflow.com › questions › 34038269
python - counting sets of numbers in a long list - Stack Overflow
L = ['128','130','140','145','','','','283','379', '','','','','','175','183','187','','','',''] #The function supports a generic empty element so you could use other separators, like tab start, size = longest_segment(L,'') print ("The longest segment starts at:\t" ,start) print ("The longest segment has length:\t",size ) #Up to this moment, there is no need to copy or keep more elements in memory. print ("The longest segment is:\t", L[start:start + size]) ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... 0 looking for a way to count combinations of numbers and how many times they appear in different lists ( sets of 2 and up )
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › set in python
Set in Python: An In-Depth Guide
October 26, 2025 - Starting with the basics and progressing to advanced concepts, we'll cover creating sets, manipulating them, and comparing them. By the end of this tutorial, you'll gain a firm understanding of how sets in Python function. A set in Python is an unordered collection of unique elements that doesn't allow duplicates.