<?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: Python - Select by attributes query issue in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-select-by-attributes-query-issue/m-p/390249#M30842</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for all the input everyone.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm sure i ended up doing a very primitive way but it is a time sensitive matter and I am very green at Python.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I ended up getting my SQL statement to work like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;field = "COUNTY_CODE"
where_clause = ('"' + field + '"' + " = " + "'" + code[0] +"'")&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I will look into the dictionaries and everything else because it seems like the way to go for the next sets of states.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 17:53:44 GMT</pubDate>
    <dc:creator>MatthewRusso</dc:creator>
    <dc:date>2021-12-11T17:53:44Z</dc:date>
    <item>
      <title>Python - Select by attributes query issue</title>
      <link>https://community.esri.com/t5/python-questions/python-select-by-attributes-query-issue/m-p/390243#M30836</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;import arcpy
code = ["007","013","014","015","017","019","021","023","027","029","031","033","035","037","039","041","043","045","047","049","051","055","059","063","065",
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "067","069","075","077","081","083","085","091","097","099","101","103","105","107","109","113","117","119","123","125"]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
cnty = ["Archuleta","Boulder","Broomfield","Chaffee","Cheyenne","Clear_Creek","Conejos","Costilla","Custer","Delta","Denver","Dolores","Douglas","Eagle","Elbert","El_Paso","Fremont","Garfield",
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Gilpin","Grand","Gunnison","Huerfano","Jefferson","Kit_Carson","Lake","La_Plata","Larimer","Logan","Mesa","Moffat","Montezuma","Montrose","Ouray","Pitkin","Prowers","Pueblo","Rio_Blanco",
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Rio_Grande","Routt","Saguache","San_Miguel","Summit","Teller","Weld","Yuma"]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("Colorado_Clip","NEW_SELECTION",""""COUNTY_CODE" = code[0]""")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management("Colorado_Clip","H:/GIS DATA/Data/Conflation/RPAM Data NAD83.gdb/Colorado/" + cnty[0],"#","0","0","0")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management('Colorado_Clip', "CLEAR_SELECTION")
&amp;nbsp;&amp;nbsp;&amp;nbsp; del cnty[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; del code[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; print cnty
&amp;nbsp;&amp;nbsp;&amp;nbsp; print code&amp;nbsp; 
except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print code[0] + " Failed"&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Above is my simple script.&lt;/P&gt;&lt;P&gt;The goal is to loop through the items on the list, select attributees and create a new shapefile based on the name in the list, clear my selection, del that item from the list and move on to the next one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Problem I am running into is in line 10 where the {where_clause} is.&amp;nbsp; The tool does not want to take a list item for the value (code[0]) is not acceptable.&amp;nbsp; Is there a way around this so i can use my list I don't want to have to type all of these out manually.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Orginially i wanted to split this file, but the size of the file prevents me from doing this.&amp;nbsp; I also have to do this for 8 more states.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyone have any ideas?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:53:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-select-by-attributes-query-issue/m-p/390243#M30836</guid>
      <dc:creator>MatthewRusso</dc:creator>
      <dc:date>2021-12-11T17:53:36Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Select by attributes query issue</title>
      <link>https://community.esri.com/t5/python-questions/python-select-by-attributes-query-issue/m-p/390244#M30837</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Matthew&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try something like this, with an iterator 'for', between the first position 0 and the 45th?? number 44.&lt;/P&gt;&lt;P&gt;It isn't necesary delete every item, the loop will read every position in every iteration.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;code = ["007","013","014","015","017","019","021","023","027","029","031","033","035","037","039","041","043","045","047","049","051","055","059","063","065",&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "067","069","075","077","081","083","085","091","097","099","101","103","105","107","109","113","117","119","123","125"]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;cnty = ["Archuleta","Boulder","Broomfield","Chaffee","Cheyenne","Clear_Creek","Conejos","Costilla","Custer","Delta","Denver","Dolores","Douglas","Eagle","Elbert","El_Paso","Fremont","Garfield",&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Gilpin","Grand","Gunnison","Huerfano","Jefferson","Kit_Carson","Lake","La_Plata","Larimer","Logan","Mesa","Moffat","Montezuma","Montrose","Ouray","Pitkin","Prowers","Pueblo","Rio_Blanco",&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Rio_Grande","Routt","Saguache","San_Miguel","Summit","Teller","Weld","Yuma"]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;try:&lt;/P&gt;&lt;P&gt;&amp;nbsp; for i in range(0, 44)&lt;/P&gt;&lt;P&gt;&amp;nbsp; arcpy.SelectLayerByAttribute_management("Colorado_Clip","NEW_SELECTION",""""COUNTY_CODE""" = " + code&lt;I&gt;)&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; ## Verify your path, if your running in windows, use the first 'copy' statement with backslashes \&lt;/P&gt;&lt;P&gt;&amp;nbsp; #arcpy.CopyFeatures_management("Colorado_Clip","H:\GIS DATA\Data\Conflation\RPAM Data NAD83.gdb\Colorado\" + cnty&lt;I&gt;,"#","0","0","0")&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; arcpy.CopyFeatures_management("Colorado_Clip","H:/GIS DATA/Data/Conflation/RPAM Data NAD83.gdb/Colorado/" + cnty&lt;I&gt;,"#","0","0","0")&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; arcpy.SelectLayerByAttribute_management('Colorado_Clip', "CLEAR_SELECTION")&lt;/P&gt;&lt;P&gt;&amp;nbsp; #del cnty[0]&lt;/P&gt;&lt;P&gt;&amp;nbsp; #del code[0]&lt;/P&gt;&lt;P&gt;&amp;nbsp; print cnty&lt;I&gt;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; print code&lt;I&gt;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;except:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print code[0] + " Failed"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope it helps.&lt;/P&gt;&lt;P&gt;Luis&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Feb 2015 14:19:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-select-by-attributes-query-issue/m-p/390244#M30837</guid>
      <dc:creator>Luis_ÁngelPascual_Camino</dc:creator>
      <dc:date>2015-02-04T14:19:19Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Select by attributes query issue</title>
      <link>https://community.esri.com/t5/python-questions/python-select-by-attributes-query-issue/m-p/390245#M30838</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi again.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reviewing your issue, the error given by the 'select' function is due to the expression:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008200; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #f6f6f6;"&gt;""""COUNTY_CODE" = code[0]"""&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;You'are passing to the function the literal "code[0]" that is an unknown variable for it. If you try:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008200; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #f6f6f6;"&gt;""""COUNTY_CODE""" = " + code[0]&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I think that will run ok with your original code because python will replace it with the value of the list in this position.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck!&lt;/P&gt;&lt;P&gt;Luis&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Feb 2015 14:27:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-select-by-attributes-query-issue/m-p/390245#M30838</guid>
      <dc:creator>Luis_ÁngelPascual_Camino</dc:creator>
      <dc:date>2015-02-04T14:27:59Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Select by attributes query issue</title>
      <link>https://community.esri.com/t5/python-questions/python-select-by-attributes-query-issue/m-p/390246#M30839</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Luis,&lt;/P&gt;&lt;P&gt;Thanks for the reply this is giving me a headache!&amp;nbsp; I just played around and came up with this also,&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;field = "COUNTY_CODE"
where_clause = ("'" + field + "'" + "= " + code[0])
print where_clause
'COUNTY_CODE'= 007&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If that doesn't work I will go the route you mentioned and get back to you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:53:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-select-by-attributes-query-issue/m-p/390246#M30839</guid>
      <dc:creator>MatthewRusso</dc:creator>
      <dc:date>2021-12-11T17:53:39Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Select by attributes query issue</title>
      <link>https://community.esri.com/t5/python-questions/python-select-by-attributes-query-issue/m-p/390247#M30840</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You might want to try:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;field = "COUNTY_CODE"
where_clause = "{} = '{}'".format(field, code[0])&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;where_clause = "COUNTY_CODE = '{}'".format(code[0])&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You don't need to put your field name in quotes, but the value itself will need to be in quotes if it is text.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I strongly encourage you to read up on &lt;A href="https://docs.python.org/2/library/string.html#string-formatting" rel="nofollow noopener noreferrer" target="_blank"&gt;Python String Formatting&lt;/A&gt;.&amp;nbsp; It is much more powerful and Pythonic for building SQL expressions than concatenating strings together.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:53:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-select-by-attributes-query-issue/m-p/390247#M30840</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-11T17:53:42Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Select by attributes query issue</title>
      <link>https://community.esri.com/t5/python-questions/python-select-by-attributes-query-issue/m-p/390248#M30841</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Matthew,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Instead of using two arrays holding your values I would suggest using a dictionary:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://yuji.wordpress.com/2008/05/14/python-basics-of-python-dictionary-and-looping-through-them/" title="https://yuji.wordpress.com/2008/05/14/python-basics-of-python-dictionary-and-looping-through-them/"&gt;Python — Basics of Python Dictionary: Looping &amp;amp; Sorting | YUJI TOMITA&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Eg:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="number4 line index3 alt1"&gt;codes = [&lt;CODE class="python string"&gt;'007'&lt;/CODE&gt;&lt;CODE class="python plain"&gt;: &lt;/CODE&gt;&lt;CODE class="python string"&gt;'Archuleta'&lt;/CODE&gt;&lt;CODE class="python plain"&gt;,&lt;/CODE&gt;&lt;CODE class="python spaces"&gt;&lt;/CODE&gt;&lt;CODE class="python string"&gt;'013'&lt;/CODE&gt;&lt;CODE class="python plain"&gt;: &lt;/CODE&gt;&lt;CODE class="python string"&gt;'Boulder'&lt;/CODE&gt;&lt;CODE class="python plain"&gt;,&lt;/CODE&gt;&lt;CODE class="python spaces"&gt;&lt;/CODE&gt;&lt;CODE class="python string"&gt;'014'&lt;/CODE&gt;&lt;CODE class="python plain"&gt;: &lt;/CODE&gt;&lt;CODE class="python string"&gt;'Broomfield']&lt;/CODE&gt;&lt;/P&gt;&lt;P class="number4 line index3 alt1"&gt;&lt;/P&gt;&lt;P class="number4 line index3 alt1"&gt;That way your county codes and names are linked to each other and you can just loop through your dictionary:&lt;/P&gt;&lt;P class="number4 line index3 alt1"&gt;&lt;/P&gt;&lt;P&gt;for key,val in codes.items():&lt;/P&gt;&lt;P&gt; print key,val&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Feb 2015 15:23:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-select-by-attributes-query-issue/m-p/390248#M30841</guid>
      <dc:creator>AnthonyGiles</dc:creator>
      <dc:date>2015-02-04T15:23:07Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Select by attributes query issue</title>
      <link>https://community.esri.com/t5/python-questions/python-select-by-attributes-query-issue/m-p/390249#M30842</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for all the input everyone.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm sure i ended up doing a very primitive way but it is a time sensitive matter and I am very green at Python.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I ended up getting my SQL statement to work like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;field = "COUNTY_CODE"
where_clause = ('"' + field + '"' + " = " + "'" + code[0] +"'")&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I will look into the dictionaries and everything else because it seems like the way to go for the next sets of states.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:53:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-select-by-attributes-query-issue/m-p/390249#M30842</guid>
      <dc:creator>MatthewRusso</dc:creator>
      <dc:date>2021-12-11T17:53:44Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Select by attributes query issue</title>
      <link>https://community.esri.com/t5/python-questions/python-select-by-attributes-query-issue/m-p/390250#M30843</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When doing this with very long lists, I find it helpful to also format the code so it's more readable. Here I organized it by the first letter.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;cnty = [
&amp;nbsp;&amp;nbsp;&amp;nbsp; "Archuleta",
&amp;nbsp;&amp;nbsp;&amp;nbsp; "Boulder","Broomfield",
&amp;nbsp;&amp;nbsp;&amp;nbsp; "Chaffee","Cheyenne","Clear_Creek","Conejos","Costilla","Custer",
&amp;nbsp;&amp;nbsp;&amp;nbsp; "Delta","Denver","Dolores","Douglas",
&amp;nbsp;&amp;nbsp;&amp;nbsp; "Eagle","Elbert","El_Paso",
&amp;nbsp;&amp;nbsp;&amp;nbsp; "Fremont",
&amp;nbsp;&amp;nbsp;&amp;nbsp; "Garfield","Gilpin","Grand","Gunnison",
&amp;nbsp;&amp;nbsp;&amp;nbsp; "Huerfano",
&amp;nbsp;&amp;nbsp;&amp;nbsp; "Jefferson",
&amp;nbsp;&amp;nbsp;&amp;nbsp; "Kit_Carson",
&amp;nbsp;&amp;nbsp;&amp;nbsp; "Lake","La_Plata","Larimer","Logan",
&amp;nbsp;&amp;nbsp;&amp;nbsp; "Mesa","Moffat","Montezuma","Montrose",
&amp;nbsp;&amp;nbsp;&amp;nbsp; "Ouray",
&amp;nbsp;&amp;nbsp;&amp;nbsp; "Pitkin","Prowers","Pueblo",
&amp;nbsp;&amp;nbsp;&amp;nbsp; "Rio_Blanco","Rio_Grande","Routt",
&amp;nbsp;&amp;nbsp;&amp;nbsp; "Saguache","San_Miguel","Summit",
&amp;nbsp;&amp;nbsp;&amp;nbsp; "Teller",
&amp;nbsp;&amp;nbsp;&amp;nbsp; "Weld",
&amp;nbsp;&amp;nbsp;&amp;nbsp; "Yuma"
]&amp;nbsp; # End cnty list&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could also organize by any other logical groups with comments to make maintenance easier.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;code = [
## Some Group
&amp;nbsp;&amp;nbsp;&amp;nbsp; "007","013","014","015","017","019","021","023",
## Another Group
&amp;nbsp;&amp;nbsp;&amp;nbsp; "027","029","031","033","035","037","039","041","043","045","047","049",
## Third Group
&amp;nbsp;&amp;nbsp;&amp;nbsp; "051","055","059","063","065","067","069",
## More Grouping
&amp;nbsp;&amp;nbsp;&amp;nbsp; "075","077","081","083","085","091","097","099",
## Still Grouping
&amp;nbsp;&amp;nbsp;&amp;nbsp; "101","103","105","107","109","113","117","119","123",
## Last Group
&amp;nbsp;&amp;nbsp;&amp;nbsp; "125"
]&amp;nbsp; # End code list&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And it works the same way with dictionaries!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:53:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-select-by-attributes-query-issue/m-p/390250#M30843</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-12-11T17:53:47Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Select by attributes query issue</title>
      <link>https://community.esri.com/t5/python-questions/python-select-by-attributes-query-issue/m-p/390251#M30844</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In addition to what &lt;A href="https://community.esri.com/migrated-users/3420" target="_blank"&gt;Joshua Bixby&lt;/A&gt;‌ shows, you could also include logic that will work no matter what the workspace is. Remember a where clause is different depending on the workspace (shapefiles, personal gdb, file geodatabase...)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;where ="{0} = '{1}'".format(arcpy.AddFieldDelimiters(fc, fld_code), code)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To create the dictionary you can do this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;dct = {}
for i in range(len(code)):
&amp;nbsp;&amp;nbsp;&amp;nbsp; dct[code&lt;I&gt;] = cnty&lt;I&gt;&lt;/I&gt;&lt;/I&gt;
print dct&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Next you copy and paste the dct behind "dct = " and you have your dict:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;dct = {'077': 'Mesa', '075': 'Logan', '023': 'Costilla', '099': 'Prowers',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '091': 'Ouray', '097': 'Pitkin', '117': 'Summit', '039': 'Elbert',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '014': 'Broomfield', '015': 'Chaffee', '113': 'San_Miguel',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '017': 'Cheyenne', '055': 'Huerfano', '031': 'Denver', '119': 'Teller',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '051': 'Gunnison', '035': 'Douglas', '123': 'Weld', '029': 'Delta',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '037': 'Eagle', '083': 'Montezuma', '019': 'Clear_Creek',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '033': 'Dolores', '063': 'Kit_Carson', '065': 'Lake', '067': 'La_Plata',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '069': 'Larimer', '081': 'Moffat', '085': 'Montrose', '027': 'Custer',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '109': 'Saguache', '007': 'Archuleta', '125': 'Yuma', '049': 'Grand',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '047': 'Gilpin', '103': 'Rio_Blanco', '045': 'Garfield', '101': 'Pueblo',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '043': 'Fremont', '107': 'Routt', '041': 'El_Paso', '105': 'Rio_Grande',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '013': 'Boulder', '021': 'Conejos', '059': 'Jefferson'}&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;to loop through the dict as shown before, use this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for code, cntr in dct.items():
&amp;nbsp;&amp;nbsp;&amp;nbsp; where ="{0} = '{1}'".format(arcpy.AddFieldDelimiters(fc, fld_code), code)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:53:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-select-by-attributes-query-issue/m-p/390251#M30844</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-11T17:53:50Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Select by attributes query issue</title>
      <link>https://community.esri.com/t5/python-questions/python-select-by-attributes-query-issue/m-p/390252#M30845</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Although I haven't used it yet, the &lt;A href="https://docs.python.org/2/library/functions.html#zip"&gt;zip() function&lt;/A&gt; should work well too. &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://stackoverflow.com/a/209854" title="http://stackoverflow.com/a/209854"&gt;Map two lists into a dictionary in Python - Stack Overflow&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 21:00:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-select-by-attributes-query-issue/m-p/390252#M30845</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2015-02-05T21:00:27Z</dc:date>
    </item>
  </channel>
</rss>

