<?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: Create dictionary and assign values in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/create-dictionary-and-assign-values/m-p/1259084#M66870</link>
    <description>&lt;P&gt;What is the entire purpose of search_feats?&amp;nbsp; why this?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;upd_row[0] = place_dict.get(search_feats[upd_row[0]], upd_row[0])&lt;/LI-CODE&gt;&lt;P&gt;your indentation on updateRow is also a level too deep.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with arcpy.da.UpdateCursor(fc,"Type") as cursor:
        for row in cursor:
            if row[0] in place_dict:
                row[0] = place_dict[row[0]]
            cursor.updateRow(row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 16 Feb 2023 20:38:57 GMT</pubDate>
    <dc:creator>DavidPike</dc:creator>
    <dc:date>2023-02-16T20:38:57Z</dc:date>
    <item>
      <title>Create dictionary and assign values</title>
      <link>https://community.esri.com/t5/python-questions/create-dictionary-and-assign-values/m-p/1259057#M66864</link>
      <description>&lt;P&gt;I am trying to use dictionary to help update a field. I have the following but I am getting an error.&lt;/P&gt;&lt;P&gt;Basically, if field "Type" has PVT, I want it to update with "Private" and if Pub, I want it to update with "Public".&lt;/P&gt;&lt;P&gt;the filed doesn't get updated. I am assuming that dict is wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

fc = r"C:\Temp\test.gdb\Testb"


search_feats ={f[0]:(f[:1] for f in arcpy.da.SearchCursor(fc,"Type")}
print(search_feats) #'OID@', 'Type'

place_dict = {"PVT": "Private",
              "Pub": "Public"
              }

with arcpy.da.UpdateCursor(fc,"Type") as upd_cur:
        for upd_row in upd_cur:
            if upd_row[0] in place_dict:
                upd_row[0] = place_dict.get(search_feats[upd_row[0]], upd_row[0])
                upd_cur.updateRow(upd_row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 20:08:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-dictionary-and-assign-values/m-p/1259057#M66864</guid>
      <dc:creator>CCWeedcontrol</dc:creator>
      <dc:date>2023-02-16T20:08:42Z</dc:date>
    </item>
    <item>
      <title>Re: Create dictionary and assign values</title>
      <link>https://community.esri.com/t5/python-questions/create-dictionary-and-assign-values/m-p/1259072#M66865</link>
      <description>&lt;P&gt;I'm not really sure what the point of search_feats is, to be honest.&lt;/P&gt;&lt;P&gt;In any case, I'd get rid of search_feats on line 16; you want to be checking place_dict, and since you're using get, you don't need to write place_dict[upd_row[0]].&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

fc = r"C:\Temp\test.gdb\Testb"


search_feats ={f[0]:(f[:1] for f in arcpy.da.SearchCursor(fc,"Type")}
print(search_feats) #'OID@', 'Type'

place_dict = {"PVT": "Private",
              "Pub": "Public"
              }

with arcpy.da.UpdateCursor(fc,"Type") as upd_cur:
        for upd_row in upd_cur:
            if upd_row[0] in place_dict:
                upd_row[0] = place_dict.get(upd_row[0], upd_row[0])
                upd_cur.updateRow(upd_row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 20:26:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-dictionary-and-assign-values/m-p/1259072#M66865</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2023-02-16T20:26:42Z</dc:date>
    </item>
    <item>
      <title>Re: Create dictionary and assign values</title>
      <link>https://community.esri.com/t5/python-questions/create-dictionary-and-assign-values/m-p/1259075#M66867</link>
      <description>&lt;P&gt;I'm not sure what purpose "search_feats" serves, but something simpler like this should work fine:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
fc = r"C:\Temp\test.gdb\Testb"
place_dict = {"PVT": "Private", "Pub": "Public" }
with arcpy.da.UpdateCursor(fc,"Type") as upd_cur:
    for upd_row in upd_cur:
        # replace the string with the matching value or leave it alone 
        upd_row[0] = place_dict.get(upd_row[0], upd_row[0])
        upd_cur.updateRow(upd_row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 20:35:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-dictionary-and-assign-values/m-p/1259075#M66867</guid>
      <dc:creator>DannyMcVey</dc:creator>
      <dc:date>2023-02-16T20:35:04Z</dc:date>
    </item>
    <item>
      <title>Re: Create dictionary and assign values</title>
      <link>https://community.esri.com/t5/python-questions/create-dictionary-and-assign-values/m-p/1259081#M66869</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/458875"&gt;@AlfredBaldenweck&lt;/a&gt;&amp;nbsp;jinx&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 20:36:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-dictionary-and-assign-values/m-p/1259081#M66869</guid>
      <dc:creator>DannyMcVey</dc:creator>
      <dc:date>2023-02-16T20:36:58Z</dc:date>
    </item>
    <item>
      <title>Re: Create dictionary and assign values</title>
      <link>https://community.esri.com/t5/python-questions/create-dictionary-and-assign-values/m-p/1259084#M66870</link>
      <description>&lt;P&gt;What is the entire purpose of search_feats?&amp;nbsp; why this?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;upd_row[0] = place_dict.get(search_feats[upd_row[0]], upd_row[0])&lt;/LI-CODE&gt;&lt;P&gt;your indentation on updateRow is also a level too deep.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with arcpy.da.UpdateCursor(fc,"Type") as cursor:
        for row in cursor:
            if row[0] in place_dict:
                row[0] = place_dict[row[0]]
            cursor.updateRow(row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 20:38:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-dictionary-and-assign-values/m-p/1259084#M66870</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2023-02-16T20:38:57Z</dc:date>
    </item>
    <item>
      <title>Re: Create dictionary and assign values</title>
      <link>https://community.esri.com/t5/python-questions/create-dictionary-and-assign-values/m-p/1259136#M66874</link>
      <description>&lt;P&gt;That was the issue, for some reason I thought I need the "search_feats" on line 16.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 21:50:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-dictionary-and-assign-values/m-p/1259136#M66874</guid>
      <dc:creator>CCWeedcontrol</dc:creator>
      <dc:date>2023-02-16T21:50:39Z</dc:date>
    </item>
  </channel>
</rss>

