frequency of values in a field

noydb jenn.duerr at gmail.com
Wed Feb 9 19:34:12 CET 2011


On Feb 9, 1:21 pm, Josh English <Joshua.R.Engl... at gmail.com> wrote:
> 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

How do you add all the records in the particular field of interest
into long_list?



More information about the Python-list mailing list