<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Update Cursor Dictionary in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/update-cursor-dictionary/m-p/1169434#M64441</link>
    <description>&lt;P&gt;Thank you and I appreciate the replay.&lt;/P&gt;&lt;P&gt;I guess I am still stuck on if I add this to my current code and if so how or do I completely do a separate updatecursor.&lt;/P&gt;&lt;P&gt;When I posted the ValueDict got cut off.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;valueDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(sjpoints1, sourceFieldsList)}
    
sourceFieldsList = ['TARGET_FID', poly,'Field1_1','Field2_1','Field3_1','Field4_2','Field4_1','Field5_1','Field6_1']

# define the field list to the original points
updateFieldsList = ['OID@', Pnt,'Field1','Field2','Field3','Field4','Field5','Field6']
                    
 #Run the Spatial Join tool, using the defaults for the join operation and join type
arcpy.SpatialJoin_analysis(ptSelection, parcel, sjpoints)

with arcpy.da.UpdateCursor(ptSelection, updateFieldsList) as updateRows:  
    for updateRow in updateRows:  
        # store the Join value of the row being updated in a keyValue variable  
        keyValue = updateRow[0]  
        # verify that the keyValue is in the Dictionary  
        if keyValue in valueDict:  
            # transfer the values stored under the keyValue from the dictionary to the updated fields.  
            for n in range (1,len(sourceFieldsList)):  
                updateRow[n] = valueDict[keyValue][n-1]  
            updateRows.updateRow(updateRow) &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 29 Apr 2022 18:16:46 GMT</pubDate>
    <dc:creator>2Quiker</dc:creator>
    <dc:date>2022-04-29T18:16:46Z</dc:date>
    <item>
      <title>Update Cursor Dictionary</title>
      <link>https://community.esri.com/t5/python-questions/update-cursor-dictionary/m-p/1168580#M64419</link>
      <description>&lt;P&gt;I am trying to pass some attributes from my layer to another but I am having an issue is with passing attributes from field 'Field4', the attributes from the layer sjpoints field 'Field4_1' doesn't match so the fc_dest layer 'Field4' and doesn't get updated.&lt;/P&gt;&lt;P&gt;The issue is FIELD4_1 has abbreviations and fc_dest has domains. How can modify my current code to check that field and if it has certain abbreviations to update with certain text, or would it be best to do a separate updatecursor and if so how can I pass the nest dictionary from the spatial join to update the fc_dest layer?&lt;/P&gt;&lt;P&gt;sjpoints - the spatial join has this&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%"&gt;TARGET_FID&lt;/TD&gt;&lt;TD width="50%"&gt;FIELD4_1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;32145&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;MH&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;&lt;P&gt;13245&lt;/P&gt;&lt;/TD&gt;&lt;TD width="50%"&gt;SFR&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;fc_dest - I need this&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%"&gt;OID&lt;/TD&gt;&lt;TD width="50%"&gt;FIELD4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;32145&lt;/TD&gt;&lt;TD&gt;MOBILE HOME&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;12345&lt;/TD&gt;&lt;TD width="50%"&gt;&lt;P&gt;SINGLE FAMILY RES&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;sourceFieldsList = ['TARGET_FID', poly,'Field1_1','Field2_1','Field3_1','Field4_2','Field4_1','Field5_1','Field6_1']

    # define the field list to the original points
    updateFieldsList = ['OID@', Pnt,'Field1','Field2','Field3','Field4','Field5','Field6]
                        
     #Run the Spatial Join tool, using the defaults for the join operation and join type
    arcpy.SpatialJoin_analysis(ptSelection, parcel, sjpoints)

    with arcpy.da.UpdateCursor(fc_dest, updateFieldsList) as updateRows:  
        for updateRow in updateRows:  
            # store the Join value of the row being updated in a keyValue variable  
            keyValue = updateRow[0]  
            # verify that the keyValue is in the Dictionary  
            if keyValue in valueDict:  
                # transfer the values stored under the keyValue from the dictionary to the updated fields.  
                for n in range (1,len(sourceFieldsList)):  
                    updateRow[n] = valueDict[keyValue][n-1]  
                updateRows.updateRow(updateRow) &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2022 22:29:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-cursor-dictionary/m-p/1168580#M64419</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2022-04-27T22:29:24Z</dc:date>
    </item>
    <item>
      <title>Re: Update Cursor Dictionary</title>
      <link>https://community.esri.com/t5/python-questions/update-cursor-dictionary/m-p/1168592#M64420</link>
      <description>&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;valueDict is undefined in your code snippet so please update if I'm missing something. If you don't have a coded value domain in the geodatabase for the values in Field4, you'll have to define them in your code. I would suggest a dictionary.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;field4_coded_values = {
    "MH": "MOBILE HOME",
    "SFR": "SINGLE FAMILY RES",
    # etc...
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then look up your abbreviation in the dictionary to get the the full value. Passing the look up value (abbreviation) in as the second argument means that is what will be returned if it doesn't exist.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;for updateRow in updateRows:
    # Look up full text of abbreviation. Return original value if not found.
    field4 = updateRow[5]
    field4_out_value = field4_coded_values.get(field4, field4)
    updateRow[5] = field4_out_value&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 27 Apr 2022 23:05:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-cursor-dictionary/m-p/1168592#M64420</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2022-04-27T23:05:54Z</dc:date>
    </item>
    <item>
      <title>Re: Update Cursor Dictionary</title>
      <link>https://community.esri.com/t5/python-questions/update-cursor-dictionary/m-p/1169434#M64441</link>
      <description>&lt;P&gt;Thank you and I appreciate the replay.&lt;/P&gt;&lt;P&gt;I guess I am still stuck on if I add this to my current code and if so how or do I completely do a separate updatecursor.&lt;/P&gt;&lt;P&gt;When I posted the ValueDict got cut off.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;valueDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(sjpoints1, sourceFieldsList)}
    
sourceFieldsList = ['TARGET_FID', poly,'Field1_1','Field2_1','Field3_1','Field4_2','Field4_1','Field5_1','Field6_1']

# define the field list to the original points
updateFieldsList = ['OID@', Pnt,'Field1','Field2','Field3','Field4','Field5','Field6']
                    
 #Run the Spatial Join tool, using the defaults for the join operation and join type
arcpy.SpatialJoin_analysis(ptSelection, parcel, sjpoints)

with arcpy.da.UpdateCursor(ptSelection, updateFieldsList) as updateRows:  
    for updateRow in updateRows:  
        # store the Join value of the row being updated in a keyValue variable  
        keyValue = updateRow[0]  
        # verify that the keyValue is in the Dictionary  
        if keyValue in valueDict:  
            # transfer the values stored under the keyValue from the dictionary to the updated fields.  
            for n in range (1,len(sourceFieldsList)):  
                updateRow[n] = valueDict[keyValue][n-1]  
            updateRows.updateRow(updateRow) &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2022 18:16:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-cursor-dictionary/m-p/1169434#M64441</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2022-04-29T18:16:46Z</dc:date>
    </item>
    <item>
      <title>Re: Update Cursor Dictionary</title>
      <link>https://community.esri.com/t5/python-questions/update-cursor-dictionary/m-p/1169499#M64443</link>
      <description>&lt;P&gt;Your logic is difficult to follow, but it looks like you're updating everything based on what is in the valueDict so maybe update the abbreviations there. Please rearrange and adjust as necessary.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;sourceFieldsList = ['TARGET_FID', poly,'Field1_1','Field2_1','Field3_1','Field4_2','Field4_1','Field5_1','Field6_1']

# define the field list to the original points
updateFieldsList = ['OID@', Pnt,'Field1','Field2','Field3','Field4','Field5','Field6']

valueDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(sjpoints1, sourceFieldsList)}

# Update abbreviation field values to full text description.
abbreviation_lookup = {
    "MH": "MOBILE HOME",
    "SFR": "SINGLE FAMILY RES",
    # etc...
}
for key, rest_of_the_fields in valueDict.items():
    # Look up full text of abbreviation. Return original value if not found.
    # I don't know which index your abbreviation data is at. Maybe it's rest_of_the_fields[6] ?
    rest_of_the_fields[5] = abbreviation_lookup.get(rest_of_the_fields[5], rest_of_the_fields[5])
    # Update the original values.
    valueDict[key] = rest_of_the_fields

# Run the Spatial Join tool, using the defaults for the join operation and join type
arcpy.SpatialJoin_analysis(ptSelection, parcel, sjpoints)

with arcpy.da.UpdateCursor(ptSelection, updateFieldsList) as updateRows:
    for updateRow in updateRows:
        # store the Join value of the row being updated in a keyValue variable
        keyValue = updateRow[0]
        # verify that the keyValue is in the Dictionary
        if keyValue in valueDict:
            # transfer the values stored under the keyValue from the dictionary to the updated fields.
            for n in range (1,len(sourceFieldsList)):
                updateRow[n] = valueDict[keyValue][n-1]
            updateRows.updateRow(updateRow)&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 29 Apr 2022 21:26:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-cursor-dictionary/m-p/1169499#M64443</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2022-04-29T21:26:20Z</dc:date>
    </item>
  </channel>
</rss>

