building a dictionary dynamically

noydb jenn.duerr at gmail.com
Sat Feb 4 13:13:06 EST 2012


How do you build a dictionary dynamically?  Doesn't seem to be an
insert object or anything.  So I need an empty dictionary that I then
want to populate with values I get from looping through a list and
grabbing some properties.  So simply, I have (fyi, arcpy = module for
interacting with gis data)

>>> inDict = {}
>>> for inFC in inFClist:
>>>     print inFC
>>>     inCount =  int(arcpy.GetCount_management(inFC).getOutput(0))


where I want to make a dictionary like {inFC: inCount, inFC:
inCount, ....}

How do I build this???

And, is dictionaries the best route go about doing a comparison, such
that in the end I will have two dictionaries, one for IN and one for
OUT, as in I'm moving data files and want to verify that the count in
each file matches between IN and OUT.

Thanks for any help!



More information about the Python-list mailing list