<?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: How can these two scripts yield different len numbers? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-can-these-two-scripts-yield-different-len/m-p/1047310#M60795</link>
    <description>&lt;P&gt;Beyond all the good feedback already provided, you never show how your "both" lists are initially created, which leaves the door open to them being different before you even started appending to them.&lt;/P&gt;</description>
    <pubDate>Wed, 14 Apr 2021 21:45:45 GMT</pubDate>
    <dc:creator>JoshuaBixby</dc:creator>
    <dc:date>2021-04-14T21:45:45Z</dc:date>
    <item>
      <title>How can these two scripts yield different len numbers?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-these-two-scripts-yield-different-len/m-p/1047234#M60789</link>
      <description>&lt;PRE&gt;&lt;SPAN&gt;for &lt;/SPAN&gt;i &lt;SPAN&gt;in &lt;/SPAN&gt;list1:&lt;BR /&gt;    &lt;SPAN&gt;if &lt;/SPAN&gt;i &lt;SPAN&gt;in &lt;/SPAN&gt;list2:&lt;BR /&gt;        inBoth1.append(i)&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;for &lt;/SPAN&gt;i &lt;SPAN&gt;in &lt;/SPAN&gt;list2:&lt;BR /&gt;    &lt;SPAN&gt;if &lt;/SPAN&gt;i &lt;SPAN&gt;in &lt;/SPAN&gt;list1:&lt;BR /&gt;        inBoth2.append(i)&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;print&lt;/SPAN&gt;(&lt;SPAN&gt;len&lt;/SPAN&gt;(inBoth1))&lt;BR /&gt;&lt;SPAN&gt;print&lt;/SPAN&gt;(&lt;SPAN&gt;len&lt;/SPAN&gt;(inBoth2))&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;For my application, I am using StreetNamesInCountyBlank1 (list1) as one list and trying to see how many match items in another list, StreetNamesCountyBlank2 (list2). However, when I reverse the script like in the example above, I get a significant difference in values. &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Apr 2021 19:37:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-these-two-scripts-yield-different-len/m-p/1047234#M60789</guid>
      <dc:creator>GeoDev</dc:creator>
      <dc:date>2021-04-14T19:37:26Z</dc:date>
    </item>
    <item>
      <title>Re: How can these two scripts yield different len numbers?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-these-two-scripts-yield-different-len/m-p/1047248#M60790</link>
      <description>&lt;P&gt;Could be that you have duplicates in one list:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;list1 = ['a', 'b', 'c', 'd']
list2 = ['a', 'b', 'c', 'd', 'c', 'aa', 'aaa', 'a', 'c']

inBoth1 = []
inBoth2 = []

for i in list1:
    if i in list2:
        inBoth1.append(i)

for i in list2:
    if i in list1:
        inBoth2.append(i)

print(len(inBoth1))
print(len(inBoth2))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;gets you 4 and 7 (because of the c's).&lt;/P&gt;&lt;P&gt;Using set on the list you get the same number:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;list1 = ['a', 'b', 'c', 'd']
list2 = ['a', 'b', 'c', 'd', 'c', 'aa', 'aaa', 'a', 'c']

inBoth1 = []
inBoth2 = []

for i in set(list1):
    if i in list2:
        inBoth1.append(i)

for i in set(list2):
    if i in list1:
        inBoth2.append(i)

print(len(inBoth1))
print(len(inBoth2))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4 and 4&lt;/P&gt;</description>
      <pubDate>Wed, 14 Apr 2021 19:51:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-these-two-scripts-yield-different-len/m-p/1047248#M60790</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-04-14T19:51:17Z</dc:date>
    </item>
    <item>
      <title>Re: How can these two scripts yield different len numbers?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-these-two-scripts-yield-different-len/m-p/1047267#M60791</link>
      <description>&lt;P&gt;If you're trying to find the "intersection" of the two lists (values that exist in both), try comparing the lists as sets.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;set(list1).intersection(set(list2))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Apr 2021 20:10:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-these-two-scripts-yield-different-len/m-p/1047267#M60791</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-04-14T20:10:34Z</dc:date>
    </item>
    <item>
      <title>Re: How can these two scripts yield different len numbers?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-these-two-scripts-yield-different-len/m-p/1047269#M60792</link>
      <description>&lt;P&gt;I would agree with JeffK, your list must have some duplications.&lt;/P&gt;&lt;P&gt;Another option is to create a dictionary of unique keys (your street name ?) : values (any value, lets say 1).&lt;/P&gt;&lt;P&gt;next looping through second feature class ( cursor) just checking if the value from that feature is in your dictionary or not (if myvalue in mydico.keys()). sth like that:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fields1 = ['field1','field2']
fc1 = StreetNamesInCountyBlank1
mydico = {}
# lets assume that my key will be the value from field1
with arcpy.da.SearchCursor(fc1, fields1) as recs:
 for rec in recs:
  if rec[0] in mydico:
   # lets count how many times the same key
   mydico[rec[0] += 1
  else:
   # the key is first time
   mydico[rec[0]] = 1

# now lets loop through second feature class
fc2 = StreetNamesInCountyBlank2
fields2 = ['field1','field2']
repetition_dico = {}
with arcpy.da.SearchCursor(fc2, fields2) as recs:
 for rec in recs:
   if rec[0] in mydico.keys():
    if rec[0] not in repetition_dico.keys():
     repetition_dico[rec[0] = 1
    else:
     # you alredy know that this is repeated, lets add count only
     repetition_dico[rec[0] += 1
# print results
print( len(repetition_dico))
for key, values in repetition_dico.items():
 print (key, value)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Apr 2021 20:15:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-these-two-scripts-yield-different-len/m-p/1047269#M60792</guid>
      <dc:creator>Tomasz_Tarchalski</dc:creator>
      <dc:date>2021-04-14T20:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: How can these two scripts yield different len numbers?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-these-two-scripts-yield-different-len/m-p/1047310#M60795</link>
      <description>&lt;P&gt;Beyond all the good feedback already provided, you never show how your "both" lists are initially created, which leaves the door open to them being different before you even started appending to them.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Apr 2021 21:45:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-these-two-scripts-yield-different-len/m-p/1047310#M60795</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-04-14T21:45:45Z</dc:date>
    </item>
  </channel>
</rss>

