How can I count how many different numbers there are in one long number?
For example: this number 1122334455
has 5 different numbers.
How can I do that in Python?
How can I count how many different numbers there are in one long number?
For example: this number 1122334455
has 5 different numbers.
How can I do that in Python?
You can do that as:
print len(set(str(s)))
The
str()
casts the int as a string
Theset()
takes the unique elements of the string and creates a set of it
Thelen()
returns the length of the set
>>> print len(set(str(s)))
5
s = 1324082304
>>> print len(set(str(s)))
6