Python, find unique values in a tuple or dictionary
Is there a python equivalent for the "array_unique" function in php?
I have to run a query on a very large table (1.5 million records, with no index!) and php can't beat the max execution time. So I am converting my php script to python, which I have never used before. my php script basically does this: gets results from database gets the number of unique values in column "X" counts how many times each unique value in column "X" occurs echos the results My php script was originally running on a smaller version of the table, I would have started in python if I would have known the "real" table was so large, python is the only language I have access to in my current environment (besides php). Thanks |
from a spamfilter i wrote...
Code:
def word_count(s): the result is placed in a dictionary, the word acts as the key and the number of times it appears is the value. hope this helps |
A python set may be useful here. This little program counts unique occurrences in a tuple and puts those unique members and their corresponding counts into a dictionary.
Code:
mytuple=(10,4,2,3,10,6,8,5,2,5,4,4,10,1,9,2) #Create a sample tuple |
All times are GMT -5. The time now is 12:31 AM. |