I'm searching for a way to count unique digits efficiently with a one liner.
For example: given the integer 623562
, return value would be 4
.
My current way of doing it is, given integer i
, im using len(set(str(i)))
.
Creating a set is time consuming. I'm going over alot of numbers so I need an efficient way.
Also, if someone can find a way to go over all the numbers with x
digits without using
range()
(and in a one liner..), I'll be glad. Memory limits me when using range
because a list is created (I assume).
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…