-6

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?

jonrsharpe
  • 107,083
  • 22
  • 201
  • 376
Skizo
  • 401
  • 2
  • 6
  • 11
  • 2
    possible duplicate of [Count unique digits one liner (efficiently)](http://stackoverflow.com/questions/10752434/count-unique-digits-one-liner-efficiently) – Ashwini Chaudhary May 02 '14 at 10:59
  • You should change the term `different numbers` to `different decimal digits` (assuming that's what you actually want to count). – barak manos May 02 '14 at 11:05

1 Answers1

4

You can do that as:

print len(set(str(s)))

The str() casts the int as a string
The set() takes the unique elements of the string and creates a set of it
The len() returns the length of the set

Examples

>>> print len(set(str(s)))
5

s = 1324082304

>>> print len(set(str(s)))
6
Community
  • 1
  • 1
sshashank124
  • 29,826
  • 8
  • 62
  • 75