<?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 Appending dictionaries to dictionary based on common attributes? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/appending-dictionaries-to-dictionary-based-on/m-p/1076390#M61610</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I have a unique situation where I have a pipe feature class with attributes of any given diameter, and I want to create a dictionary where the key for each diameter of pipe greater than a set diameter, and append dictionaries of pipe materials and overall lengths for each material. I have something scripted that gets me fairly close, but for some reason it keeps updating the unique key for the diameter and not appending additional dictionaries to that key.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;for fc in listed_fcs:

        geometryType = arcpy.Describe(fc).shapeType
        #print (geometryType)

        fc_fields = []

        
        important_fields = [list of specific fields]
        important_FAvalues = [list of important attributes in field A]
        important_FBvalues = [list of important attributes in field B]

        fcsname = os.path.basename(fc)
        name = os.path.splitext(fcsname)
        y = name[1].lstrip('.')
        print ('\n',y)

        i = 0
        t = 0
        d = {}
        v = {}
        #counts = arcpy.GetCount_management(fc)

        #______________Loop through databases that are not stormwater__________#
        if y not in [fc list]:
            allfields = arcpy.ListFields(fc)
            for field in allfields:
                if field.name in important_fields:
                    #print (field.name)
                    fc_fields.append(field.name)
                    
            fcFields_len = len(fc_fields)

            #_____________Loop through two set fcs____________#

            if  y in [specified list of fcs]:
                
                fc_fields_wLength = fc_fields + ['SHAPE@LENGTH']

                ImpA = fc_fields_wLength.index(important_fields[1])
                ImpB = fc_fields_wLength.index(important_fields[2]) or fc_fields_wLength.index(important_fields[3])
                ImpD = fc_fields_wLength.index(important_fields[4])
                ImpE = fc_fields_wLength.index(important_fields[5])

                with arcpy.da.SearchCursor(fc, fc_fields_wLength) as scur:
                    for s in scur:
                        if s[ImpA] in important_FAvalues and s[ImpB] in important_FBvalues:
                            i = i + 1
                            t = t + s[-1]
                            m = 0
                            if  y not in [waterin_fcs[3], water_upper[3]] :
                                if s[ImpD] is None:
                                    #d[s[ImpD]] = {s[ImpE]:m + s[-1]}
                                    pass
                                elif s[ImpD] is not None:
                                    if int(s[ImpD]) &amp;gt;= 8 and int(s[ImpD]) &amp;lt;= 42:
                                        m = m + s[-1]
                                        v[s[ImpE]] = (m)
                                        
                            else:
                                if s[ImpD] is None:
                                    #d[s[ImpD]] = {s[ImpE]:m + s[-1]}
                                    pass
                                elif s[ImpD] is not None:
                                    if s[ImpD] &amp;gt;= 2.5:
                                        m = m + s[-1]
                                        v[s[ImpE]] = (m)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-center"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;This is a small snippet of the actual code. The actual code itself is increasingly too long to post.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So is there a way to script this so that for each unique pipe diameter, I get all of the materials of that pipe plus the total distances, and append that dictionary(s) to the dictionary for the pipe diameter?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would greatly appreciate it if anyone could assist me with this. I have spent several hours trying to figure it out but I can't seem to.&lt;/P&gt;</description>
    <pubDate>Wed, 07 Jul 2021 19:37:16 GMT</pubDate>
    <dc:creator>RPGIS</dc:creator>
    <dc:date>2021-07-07T19:37:16Z</dc:date>
    <item>
      <title>Appending dictionaries to dictionary based on common attributes?</title>
      <link>https://community.esri.com/t5/python-questions/appending-dictionaries-to-dictionary-based-on/m-p/1076390#M61610</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I have a unique situation where I have a pipe feature class with attributes of any given diameter, and I want to create a dictionary where the key for each diameter of pipe greater than a set diameter, and append dictionaries of pipe materials and overall lengths for each material. I have something scripted that gets me fairly close, but for some reason it keeps updating the unique key for the diameter and not appending additional dictionaries to that key.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;for fc in listed_fcs:

        geometryType = arcpy.Describe(fc).shapeType
        #print (geometryType)

        fc_fields = []

        
        important_fields = [list of specific fields]
        important_FAvalues = [list of important attributes in field A]
        important_FBvalues = [list of important attributes in field B]

        fcsname = os.path.basename(fc)
        name = os.path.splitext(fcsname)
        y = name[1].lstrip('.')
        print ('\n',y)

        i = 0
        t = 0
        d = {}
        v = {}
        #counts = arcpy.GetCount_management(fc)

        #______________Loop through databases that are not stormwater__________#
        if y not in [fc list]:
            allfields = arcpy.ListFields(fc)
            for field in allfields:
                if field.name in important_fields:
                    #print (field.name)
                    fc_fields.append(field.name)
                    
            fcFields_len = len(fc_fields)

            #_____________Loop through two set fcs____________#

            if  y in [specified list of fcs]:
                
                fc_fields_wLength = fc_fields + ['SHAPE@LENGTH']

                ImpA = fc_fields_wLength.index(important_fields[1])
                ImpB = fc_fields_wLength.index(important_fields[2]) or fc_fields_wLength.index(important_fields[3])
                ImpD = fc_fields_wLength.index(important_fields[4])
                ImpE = fc_fields_wLength.index(important_fields[5])

                with arcpy.da.SearchCursor(fc, fc_fields_wLength) as scur:
                    for s in scur:
                        if s[ImpA] in important_FAvalues and s[ImpB] in important_FBvalues:
                            i = i + 1
                            t = t + s[-1]
                            m = 0
                            if  y not in [waterin_fcs[3], water_upper[3]] :
                                if s[ImpD] is None:
                                    #d[s[ImpD]] = {s[ImpE]:m + s[-1]}
                                    pass
                                elif s[ImpD] is not None:
                                    if int(s[ImpD]) &amp;gt;= 8 and int(s[ImpD]) &amp;lt;= 42:
                                        m = m + s[-1]
                                        v[s[ImpE]] = (m)
                                        
                            else:
                                if s[ImpD] is None:
                                    #d[s[ImpD]] = {s[ImpE]:m + s[-1]}
                                    pass
                                elif s[ImpD] is not None:
                                    if s[ImpD] &amp;gt;= 2.5:
                                        m = m + s[-1]
                                        v[s[ImpE]] = (m)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-center"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;This is a small snippet of the actual code. The actual code itself is increasingly too long to post.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So is there a way to script this so that for each unique pipe diameter, I get all of the materials of that pipe plus the total distances, and append that dictionary(s) to the dictionary for the pipe diameter?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would greatly appreciate it if anyone could assist me with this. I have spent several hours trying to figure it out but I can't seem to.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jul 2021 19:37:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/appending-dictionaries-to-dictionary-based-on/m-p/1076390#M61610</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2021-07-07T19:37:16Z</dc:date>
    </item>
    <item>
      <title>Re: Appending dictionaries to dictionary based on common attributes?</title>
      <link>https://community.esri.com/t5/python-questions/appending-dictionaries-to-dictionary-based-on/m-p/1076407#M61613</link>
      <description>&lt;P&gt;perhaps sharing your code so far would help to debug.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jul 2021 18:01:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/appending-dictionaries-to-dictionary-based-on/m-p/1076407#M61613</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-07-07T18:01:12Z</dc:date>
    </item>
    <item>
      <title>Re: Appending dictionaries to dictionary based on common attributes?</title>
      <link>https://community.esri.com/t5/python-questions/appending-dictionaries-to-dictionary-based-on/m-p/1076450#M61614</link>
      <description>&lt;P&gt;Hi David,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I updated the post to include a snippet of the code. Let me know if this is a supplemental amount of information to work with.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jul 2021 19:38:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/appending-dictionaries-to-dictionary-based-on/m-p/1076450#M61614</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2021-07-07T19:38:40Z</dc:date>
    </item>
  </channel>
</rss>

