Tuesday, June 2, 2009

Finding Unique Values in Python

Here is a nice script example of how to find a unique value.

def UniqueValueList(value, vallist):
found = False
for listItem in vallist:
if listItem == value:
found = True
if found == False:
return vallist

This returns a list of values. The inputs are the value you want to see if it's unique and the array list you are storing your values in.

To declare the python array all you need to do is the following:
ValueList = []

So the proper call of this function would be
ValueList = UniqueValueList(value, ValueList)