Populating Empty Dictionaries

This weeks module took me the longest to complete so far in this course.  I definitely took a lot away from the experience and feel extremely accomplished; I was able to problem solve my way out of a lot of dead ends and errors.  The script creates a fGDB and copies shapefiles from a filepath into the fGDB.  After, a search cursor is used to iterate over the rows of a copied shapefile for a specific attribute of a field.  Lastly, an empty dictionary is created with the keys and values populated from two different fields from the results of Search cursor.

Formatting for loops makes a lot more sense after this lab.  A for loop was used with a Search Cursor to only print the cities containing 'County Seat' as an attribute in a specific field of that shapefile.  What took me awhile to correct was populating an empty dictionary in the same fashion.  My keys and values variables that were initially being used to update the empty dictionary were before the for loop in this block of code.  As a result, the dictionary was populating with the values from the list of fields used in the Search Cursor earlier.

To fix this, I established the keys and values variables within the for loop.  Also within the for loop is Update() method to populate the dictionary with the keys and values within the parameters of the SearchCursor().  I'm extremely reliant on Google to troubleshoot errors and have learned a lot from surfing the web for answers.  The discussion boards in this course have been very helpful throughout the past weeks.   Researching a lot of these errors has been a great way to gain more exposure to the fundamentals of python.  I'll have to keep working on my vocabulary of methods and functions, but I've already gained a lot of practical knowledge in just a few short weeks.







Comments

Popular Posts