<?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: SearchCursor, create unique lists, convert to dictionary in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/searchcursor-create-unique-lists-convert-to/m-p/662940#M51523</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ah, yes, forgot about that. The actions for the original post are at the top of the post off to the right (under the following, share, bookmark, and like options).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 05 Feb 2015 17:53:37 GMT</pubDate>
    <dc:creator>BlakeTerhune</dc:creator>
    <dc:date>2015-02-05T17:53:37Z</dc:date>
    <item>
      <title>SearchCursor, create unique lists, convert to dictionary</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-create-unique-lists-convert-to/m-p/662932#M51515</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fc = 'Texas'
field1 = "COUNTY_CODE"
field2 = "NAME10" 
list1 = []&amp;nbsp;&amp;nbsp; 
list2 = [] 
rows = arcpy.SearchCursor(fc)

for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; list1.append(row.getValue(field1))
&amp;nbsp;&amp;nbsp;&amp;nbsp; list2.append(row.getValue(field2))
else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "loop failed"

#Get Unique Values from the List&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
uSet1 = set(list1)
uSet2 = set(list2)

#Convert the set to a list
uList1 = list(uSet1)
uList2 = list(uSet2)

#Print The list
print uList1
print uList2

#Create Dictionary from the 2 lists and print results
from itertools import chain, repeat
d = dict(zip(uList1, chain(uList2, repeat(None))))

for key,val in d.items():
&amp;nbsp;&amp;nbsp;&amp;nbsp; print key,val&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:01:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-create-unique-lists-convert-to/m-p/662932#M51515</guid>
      <dc:creator>MatthewRusso</dc:creator>
      <dc:date>2021-12-12T04:01:54Z</dc:date>
    </item>
    <item>
      <title>Re: SearchCursor, create unique lists, convert to dictionary</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-create-unique-lists-convert-to/m-p/662933#M51516</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Don't know what happened but i can't find the post editor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basically I am getting an error:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Runtime error &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Traceback (most recent call last):&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; File "&amp;lt;string&amp;gt;", line 12, in &amp;lt;module&amp;gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\arcobjects\arcobjects.py", line 1044, in getValue&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return convertArcObjectToPythonObject(self._arc_object.GetValue(*gp_fixargs(args)))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;RuntimeError: ERROR 999999: Error executing function.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to create 2 list via the search cursor, then put them in a dictionary.&amp;nbsp; I might be doing this completely wrong but what I am doing makes sense to me.&amp;nbsp; I can run through the first list no problem, but get an error when i add the second list.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help would be awesome.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 17:15:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-create-unique-lists-convert-to/m-p/662933#M51516</guid>
      <dc:creator>MatthewRusso</dc:creator>
      <dc:date>2015-02-05T17:15:47Z</dc:date>
    </item>
    <item>
      <title>Re: SearchCursor, create unique lists, convert to dictionary</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-create-unique-lists-convert-to/m-p/662934#M51517</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Post manage options (edit and delete) are under the Actions menu at the extreme bottom left of each post. &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 17:22:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-create-unique-lists-convert-to/m-p/662934#M51517</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2015-02-05T17:22:51Z</dc:date>
    </item>
    <item>
      <title>Re: SearchCursor, create unique lists, convert to dictionary</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-create-unique-lists-convert-to/m-p/662935#M51518</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It's showing up for my reply but not the main post &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/sad.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 17:25:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-create-unique-lists-convert-to/m-p/662935#M51518</guid>
      <dc:creator>MatthewRusso</dc:creator>
      <dc:date>2015-02-05T17:25:08Z</dc:date>
    </item>
    <item>
      <title>Re: SearchCursor, create unique lists, convert to dictionary</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-create-unique-lists-convert-to/m-p/662936#M51519</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The error probably refers to the problem obtaining a value using getValue. You may check the name of the field (does it exist) and the content of the field (empty values?).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Are you using 10.0? If you have access to 10.1 (SP1) you can use the data access module that makes life a lot easier:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To create a dictionary from OID and an arbitrary field:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fc = r'C:\path\to\your\featureclass\or\table' 
fld_oid = arcpy.Describe(fc).OIDfieldname 
fld_other = 'afieldname' 
d = {r[0]: r[1] for r in arcpy.da.SearchCursor(fc, (fld_oid, fld_other))} &lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What should the dictionary contain?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Some more info and useful snippets can be found here: &lt;A href="https://community.esri.com/docs/DOC-1927" target="_blank"&gt;Some Python Snippets&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:01:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-create-unique-lists-convert-to/m-p/662936#M51519</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-12T04:01:56Z</dc:date>
    </item>
    <item>
      <title>Re: SearchCursor, create unique lists, convert to dictionary</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-create-unique-lists-convert-to/m-p/662937#M51520</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dictionary should contain the County ID/County Name to be used later to run through an extraction process.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am on 10.1 SP1 Adv Copy&lt;/P&gt;&lt;P&gt;fc = "Texas" is a fc in a geodatabase&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am pulling parcel data out of 10 states so i want to pull the info out of the tables for my selection process and naming convention.&amp;nbsp; I have to do this on a weekly basis coming up so I am trying to have a script to run overnight.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The parcel file is joined to another file, could this effect it?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 17:37:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-create-unique-lists-convert-to/m-p/662937#M51520</guid>
      <dc:creator>MatthewRusso</dc:creator>
      <dc:date>2015-02-05T17:37:54Z</dc:date>
    </item>
    <item>
      <title>Re: SearchCursor, create unique lists, convert to dictionary</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-create-unique-lists-convert-to/m-p/662938#M51521</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Does using a search cursor in a list (dictionary) comprehension like this automatically close the cursor when it's finished like when using it in a with block?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EDIT:&lt;/P&gt;&lt;P&gt;I did a quick test and it looks like the lock does go away. Spiffy!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 17:41:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-create-unique-lists-convert-to/m-p/662938#M51521</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2015-02-05T17:41:14Z</dc:date>
    </item>
    <item>
      <title>Re: SearchCursor, create unique lists, convert to dictionary</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-create-unique-lists-convert-to/m-p/662939#M51522</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try this and see if it works:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
# set your workspace
# (or not if you run this in the Python Window and the layer Texas is in your TOC)
# arcpyy.env.workspace = r"drive:\path\to\your\input\fgdb.gdb" # or folder

fc = 'Texas'
field1 = "COUNTY_CODE"
field2 = "NAME10"

# create dictionary
d = {r[0]: r[1] for r in arcpy.da.SearchCursor(fc, (field1, field2))}

for key,val in d.items():
&amp;nbsp;&amp;nbsp;&amp;nbsp; print key,val&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:01:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-create-unique-lists-convert-to/m-p/662939#M51522</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-12T04:01:59Z</dc:date>
    </item>
    <item>
      <title>Re: SearchCursor, create unique lists, convert to dictionary</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-create-unique-lists-convert-to/m-p/662940#M51523</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ah, yes, forgot about that. The actions for the original post are at the top of the post off to the right (under the following, share, bookmark, and like options).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 17:53:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-create-unique-lists-convert-to/m-p/662940#M51523</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2015-02-05T17:53:37Z</dc:date>
    </item>
    <item>
      <title>Re: SearchCursor, create unique lists, convert to dictionary</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-create-unique-lists-convert-to/m-p/662941#M51524</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;/PRE&gt;&lt;P&gt;So i'm testing the da.searchcursor right now, i believe there is some issue with joining the 2 Feature class tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;my first test i ran with 1 of my fields the "COUNTY_CODE" and it worked, created a unique list fine&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I then joined my files and ran the exact same script and it said "Cannot find field 'COUNTY_CODE'"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to export to a new file to see if the join was acting like a temp file or something, kind of strange.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is where I am at.&amp;nbsp; I don't want to make it a dictionary right of the bat so i can test it vs. all the states.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fc = 'Texas2'
field1 = "COUNTY_CODE"
field2 = "NAME10" 

list1 = [row[0] for row in arcpy.da.SearchCursor(fc, field1)]
list2 = [row[0] for row in arcpy.da.SearchCursor(fc, field2)]

#Get Unique Values
uValue1 = set(list1)
uValue2 = set(list2)
#Convert to a List
uList1 = list(uValue1)
uList2 = list(uValue2)

print(uValue1)
print(uValue2)

#Create Dictionary from the 2 lists and print results
from itertools import chain, repeat
d = dict(zip(uList1, chain(uList2, repeat(None))))

for key,val in d.items():
&amp;nbsp;&amp;nbsp;&amp;nbsp; print key,val&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:02:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-create-unique-lists-convert-to/m-p/662941#M51524</guid>
      <dc:creator>MatthewRusso</dc:creator>
      <dc:date>2021-12-12T04:02:02Z</dc:date>
    </item>
    <item>
      <title>Re: SearchCursor, create unique lists, convert to dictionary</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-create-unique-lists-convert-to/m-p/662942#M51525</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Maybe you have to call your field name as "featureclass.fieldname" beacuse that's how ArcMap renames when you join. Try using &lt;A href="http://resources.arcgis.com/en/help/main/10.2/018v/018v00000012000000.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;ListFields&lt;/A&gt; to print the name of the fields on the feature class you're running the SearchCursor on (Texas2) so you can see what you're working with.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fields = arcpy.ListFields(fc)
for f in fields:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print f.name&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EDIT:&lt;/P&gt;&lt;P&gt;Are you doing the join in Python?&lt;/P&gt;&lt;P&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/0017/001700000064000000.htm" title="http://resources.arcgis.com/en/help/main/10.1/0017/001700000064000000.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;ArcGIS Help 10.1 - Add Join (Data Management)&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:02:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-create-unique-lists-convert-to/m-p/662942#M51525</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-12-12T04:02:04Z</dc:date>
    </item>
    <item>
      <title>Re: SearchCursor, create unique lists, convert to dictionary</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-create-unique-lists-convert-to/m-p/662943#M51526</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;EDIT: I have joined it via GP Tool&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ok, progress has been made.&amp;nbsp; I ran what you listed above and it looks like my fields are showing up as seperate files still(guessing because of the Join)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried to make the join permenate by exporting/copying feature but it isn't working since the fields are still linking to the joined file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Notice the print of f.name&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #9c9c9c;"&gt;#Texas FC&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Texas_COUNTY_CODE&lt;/P&gt;&lt;P&gt;Texas_STATE_CODE&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#Texas_Counties FC&lt;/P&gt;&lt;P&gt;Texas_Counties_FID&lt;/P&gt;&lt;P&gt;Texas_Counties_STATEFP10&lt;/P&gt;&lt;P&gt;Texas_Counties_COUNTYFP10&lt;/P&gt;&lt;P&gt;Texas_Counties_NAME10&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It seems like it is working, just can't find that field because it is not displaying as the "Texas" FC&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 18:53:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-create-unique-lists-convert-to/m-p/662943#M51526</guid>
      <dc:creator>MatthewRusso</dc:creator>
      <dc:date>2015-02-05T18:53:58Z</dc:date>
    </item>
    <item>
      <title>Re: SearchCursor, create unique lists, convert to dictionary</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-create-unique-lists-convert-to/m-p/662944#M51527</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try doing the join in Python using &lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;CODE&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/0017/001700000064000000.htm"&gt;&lt;SPAN class="n"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;AddJoin_management&lt;SPAN style="font-family: 'courier new', courier;"&gt;()&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/A&gt;&lt;/CODE&gt;&lt;/SPAN&gt; (see example 2 at the bottom). Once you've done the join, then print the field names and see what you need to use for the search cursor.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 19:02:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-create-unique-lists-convert-to/m-p/662944#M51527</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2015-02-05T19:02:27Z</dc:date>
    </item>
    <item>
      <title>Re: SearchCursor, create unique lists, convert to dictionary</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-create-unique-lists-convert-to/m-p/662945#M51528</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;After further investigation, I should clarify that the feature class needs to be a &lt;A href="http://resources.arcgis.com/en/help/main/10.2/0017/00170000006p000000.htm"&gt;feature layer&lt;/A&gt; before you can do the join. Once you do the join, the field names on the feature layer are indeed "featureclassname.fieldname".&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 20:45:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-create-unique-lists-convert-to/m-p/662945#M51528</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2015-02-05T20:45:26Z</dc:date>
    </item>
  </channel>
</rss>

