"V.C.Sekhar" vcsekhar007@... wrote:
Subject: Array programming
Hi there,
I couldnt get to do the following task using Python. Can some
pls
suggest me a way to do this.
I have an array with duplicate strings filled in it. Now am
looking for
a way to extract only the DISTINCT Values from that array.
Could some one pls help me out.
Hmmm... well the definition of the "best" way would depend on how
important readability, speed etc. were to you, and somewhat a matter of
taste as well.
For me, the most "natural" implementation would be
Create an empty list.
Iterate over the elements of the array.
For each element of the array if it is not in the list then add it.
Then you end up with a list of distinct elements.
Eg.
unique = []
for elt in array_of_strings:
if elt not in unique: unique.append(elt)