Appending dictionaries to dictionary based on common attributes?

07-07-2021 10:29 AM
Regular Contributor



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.


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 in important_fields:
                    #print (
            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]}
                                elif s[ImpD] is not None:
                                    if int(s[ImpD]) >= 8 and int(s[ImpD]) <= 42:
                                        m = m + s[-1]
                                        v[s[ImpE]] = (m)
                                if s[ImpD] is None:
                                    #d[s[ImpD]] = {s[ImpE]:m + s[-1]}
                                elif s[ImpD] is not None:
                                    if s[ImpD] >= 2.5:
                                        m = m + s[-1]
                                        v[s[ImpE]] = (m)


This is a small snippet of the actual code. The actual code itself is increasingly too long to post. 


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?


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.

0 Kudos
2 Replies
MVP Frequent Contributor

perhaps sharing your code so far would help to debug.

Regular Contributor

Hi David,


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.

0 Kudos