Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading