Search code examples
pythonnumbersdigits

How would I find get the distinct digits of a number Python


I need to find all the distinct digits of a number and put them in an array, without looping.

I have already tried looping, but it is too slow.

If the number was 4884, then I would get [4,8] as an output.


Solution

  • >>> r = set(map(int, str(4884))) 
    >>> r
    {8, 4}