Question

How do I remove duplicate values from an array in Python?

  • 12 August 2023
  • 7 replies
  • 67 views

Userlevel 3
Badge +3

I have an array of values that looks like this: 

F11.20,Z51.81, 80307 99213 , F32.9,F90.0,F43.12, F11.20, F32.9,F41.1,F90.0

 

I want to remove the duplicate values; so I found this help article on the Community site:

 

The directions seem easy enough to follow; here is my action:

 

 

My result is this: 

 

 

Help !!!! Please

And thanks

 

gml


7 replies

Userlevel 7
Badge +14

Hi @blueguy 

Good question.

You need to remove the bottom ‘output’ line since that’s a duplicate.

 

Userlevel 3
Badge +3

you are the best!!

thank you!

 

gml

Userlevel 3
Badge +3

Another question, please.

 

in the 1st line of code you are splitting by a comma as seen here:

 

let Set = inputData.Set.split(","); // creates array by splitting Input Data variable at commas

 

Can you split by a space or “ “?

 

gml

Userlevel 3
Badge +3

the answer is YES

Userlevel 3
Badge +3

Troy:

Is there a way to identify the number of “Distinct” values that were outputted? in the example below there were 6 values.

Once I identify the unique values (as we have done), I would like to put those values back together as a string and with each value separated by a comma

Userlevel 7
Badge +14

@blueguy 

To get the count.

Count = Set.length;

 

To join with commas.

Set.join(",");

 

Userlevel 3
Badge +3

Thanks!  let me see what I can do with those!

 

gml

Reply