Search code examples
pythonprintingnumbers

Printing the number of different numbers in python


I would like to ask a question please regarding printing the number of different numbers in python.

for example: Let us say that I have the following list:

X = [5, 5, 5] 

Since here we have only one number, I want to build a code that can recognize that we have only one number here so the output must be:

1
The number is: 5 

Let us say that I have the following list:

X = [5,4,5]

Since here we have two numbers (5 and 4), I want to the code to recognize that we have only two numbers here so the output must be:

2
The numbers are: 4, 5

Let us say that I have the following list:

X = [24,24,24,24,24,24,24,24,26,26,26,26,26,26,26,26]

Since here we have two numbers (24 and 26), I want to the code to recognize that we have only two numbers here so the output must be:

2
The numbers are: 24, 26

Solution

  • You can try numpy.unique, and use len() on the result