frequency of values in a field

Josh English Joshua.R.English at gmail.com
Wed Feb 9 19:21:47 CET 2011


On Wednesday, February 9, 2011 9:52:27 AM UTC-8, noydb wrote:

> 
> So it seems the idea is to add all the records in the particular field
> of interest into a list (record).  How does one do this in pure
> Python?
> Normally in my work with gis/arcgis sw, I would do a search cursor on
> the DBF file and add each value in the particular field into a list
> (to populate records above).  Something like:
> 

I'm not sure I understand what you mean by "pure Python." Decimal and collections are part of the standard library. 

If you mean "use no imports whatsoever," the code would look like:

counts = {}
for thing in long_list:
  key = make_key(thing)
  if key in counts:
    counts[key] += 1
  else:
    counts[key] = 1

But using a few imports is cleaner and just as easy to troubleshoot.


Josh



More information about the Python-list mailing list