Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

83F18EFBC3C5269DDF108A26B5109A48226F3099

item_list = [
{'qmaQuoteAssemblyID': 0, 'qmaParentAssemblyID': 0, 'qmaPartID': 'RACK S9 ', 'qmaLevel': 1, 'qmaQuantityPerParent': 1.00000, 'qmaPartShortDescription': '12U x 600 x 650 Professional Rack '}, 
{'qmaQuoteAssemblyID': 1, 'qmaParentAssemblyID': 0, 'qmaPartID': 'COLOUR ', 'qmaLevel': 2, 'qmaQuantityPerParent': 1.00000, 'qmaPartShortDescription': '. '}, 
{'qmaQuoteAssemblyID': 2, 'qmaParentAssemblyID': 0, 'qmaPartID': 'FRAME ', 'qmaLevel': 2, 'qmaQuantityPerParent': 1.00000, 'qmaPartShortDescription': '. '}, 
{'qmaQuoteAssemblyID': 3, 'qmaParentAssemblyID': 0, 'qmaPartID': 'MOUNTING ', 'qmaLevel': 2, 'qmaQuantityPerParent': 1.00000, 'qmaPartShortDescription': '. '}, 
{'qmaQuoteAssemblyID': 4, 'qmaParentAssemblyID': 0, 'qmaPartID': 'FRONT DOOR ', 'qmaLevel': 2, 'qmaQuantityPerParent': 1.00000, 'qmaPartShortDescription': '. '}, 
{'qmaQuoteAssemblyID': 5, 'qmaParentAssemblyID': 0, 'qmaPartID': 'REAR DOOR ', 'qmaLevel': 2, 'qmaQuantityPerParent': 1.00000, 'qmaPartShortDescription': '. '}, 
{'qmaQuoteAssemblyID': 6, 'qmaParentAssemblyID': 0, 'qmaPartID': 'LEFT SIDE PANEL ', 'qmaLevel': 2, 'qmaQuantityPerParent': 1.00000, 'qmaPartShortDescription': '(when viewed from front of rack) '}, 
{'qmaQuoteAssemblyID': 7, 'qmaParentAssemblyID': 0, 'qmaPartID': 'RIGHT SIDE PANEL ', 'qmaLevel': 2, 'qmaQuantityPerParent': 1.00000, 'qmaPartShortDescription': '(when viewed from front of rack) '}, 
{'qmaQuoteAssemblyID': 8, 'qmaParentAssemblyID': 0, 'qmaPartID': 'ACCESSORIES ', 'qmaLevel': 2, 'qmaQuantityPerParent': 1.00000, 'qmaPartShortDescription': '. '}, 
{'qmaQuoteAssemblyID': 9, 'qmaParentAssemblyID': 0, 'qmaPartID': 'PDU ', 'qmaLevel': 2, 'qmaQuantityPerParent': 1.00000, 'qmaPartShortDescription': '. '}, 
{'qmaQuoteAssemblyID': 10, 'qmaParentAssemblyID': 0, 'qmaPartID': 'FRONT VCM ', 'qmaLevel': 2, 'qmaQuantityPerParent': 1.00000, 'qmaPartShortDescription': '. '}, 
{'qmaQuoteAssemblyID': 11, 'qmaParentAssemblyID': 0, 'qmaPartID': 'REAR VCM ', 'qmaLevel': 2, 'qmaQuantityPerParent': 1.00000, 'qmaPartShortDescription': '. '}, 
{'qmaQuoteAssemblyID': 12, 'qmaParentAssemblyID': 0, 'qmaPartID': 'PACKAGING ', 'qmaLevel': 2, 'qmaQuantityPerParent': 1.00000, 'qmaPartShortDescription': '. '}, 
{'qmaQuoteAssemblyID': 21, 'qmaParentAssemblyID': 1, 'qmaPartID': '800-560192 ', 'qmaLevel': 3, 'qmaQuantityPerParent': 1.00000, 'qmaPartShortDescription': 'Colour: Mannex Suede '}, 
{'qmaQuoteAssemblyID': 22, 'qmaParentAssemblyID': 2, 'qmaPartID': '1A000 ', 'qmaLevel': 3, 'qmaQuantityPerParent': 1.00000, 'qmaPartShortDescription': 'Label 19" Rack Container Commercial '}, 
{'qmaQuoteAssemblyID': 23, 'qmaParentAssemblyID': 2, 'qmaPartID': '0R000P ', 'qmaLevel': 3, 'qmaQuantityPerParent': 1.00000, 'qmaPartShortDescription': 'Frame Top x 600 x 650 Typ 0P '}, 
{'qmaQuoteAssemblyID': 24, 'qmaParentAssemblyID': 2, 'qmaPartID': '0S0221 ', 'qmaLevel': 3, 'qmaQuantityPerParent': 4.00000, 'qmaPartShortDescription': 'Frame Vertical 12U H2 Type 1 '}, 
{'qmaQuoteAssemblyID': 25, 'qmaParentAssemblyID': 2, 'qmaPartID': '0T000P ', 'qmaLevel': 3, 'qmaQuantityPerParent': 1.00000, 'qmaPartShortDescription': 'Frame Bottom x 600 x 650 Type 0P '}, 
{'qmaQuoteAssemblyID': 27, 'qmaParentAssemblyID': 3, 'qmaPartID': '0E220 ', 'qmaLevel': 3, 'qmaQuantityPerParent': 1.00000, 'qmaPartShortDescription': 'Base Pro. Levelling Feet + Mount Plate Kit GA '}, 
{'qmaQuoteAssemblyID': 28, 'qmaParentAssemblyID': 3, 'qmaPartID': '03020D0 ', 'qmaLevel': 3, 'qmaQuantityPerParent': 4.00000, 'qmaPartShortDescription': 'Gusset Mount Rail 12U x 600 '}, 
{'qmaQuoteAssemblyID': 29, 'qmaParentAssemblyID': 4, 'qmaPartID': 'NO DOOR ', 'qmaLevel': 3, 'qmaQuantityPerParent': 1.00000, 'qmaPartShortDescription': 'No Door Required '}, 
{'qmaQuoteAssemblyID': 34, 'qmaParentAssemblyID': 5, 'qmaPartID': 'NO DOOR ', 'qmaLevel': 3, 'qmaQuantityPerParent': 1.00000, 'qmaPartShortDescription': 'No Door Required '}, 
{'qmaQuoteAssemblyID': 35, 'qmaParentAssemblyID': 27, 'qmaPartID': '800-250215 ', 'qmaLevel': 4, 'qmaQuantityPerParent': 4.00000, 'qmaPartShortDescription': 'Levelling Feet '}, 
{'qmaQuoteAssemblyID': 36, 'qmaParentAssemblyID': 35, 'qmaPartID': '800-250137 ', 'qmaLevel': 5, 'qmaQuantityPerParent': 1.00000, 'qmaPartShortDescription': ';;;;;Leveling;Foot;Plate; '}, 
{'qmaQuoteAssemblyID': 37, 'qmaParentAssemblyID': 28, 'qmaPartID': '127040 ', 'qmaLevel': 4, 'qmaQuantityPerParent': 1.00000, 'qmaPartShortDescription': 'Mount Rail Gusset 12U Universal '}, 
{'qmaQuoteAssemblyID': 38, 'qmaParentAssemblyID': 28, 'qmaPartID': '127014 ', 'qmaLevel': 4, 'qmaQuantityPerParent': 1.00000, 'qmaPartShortDescription': '12U;0600;;;C;Mount;Rail; '}] 

dfp = {}
for item in item_list:
	dfp[item['qmaQuoteAssemblyID']] = item

items = {}
for item in item_list:
	parent_dict = items.setdefault(item['qmaParentAssemblyID'], {})
	child_dict = items.setdefault(item['qmaQuoteAssemblyID'], {})
	if item['qmaQuoteAssemblyID'] not in parent_dict:
		parent_dict[item['qmaQuoteAssemblyID']] = child_dict

def print_dictionary(dictionary, root, level = 0.0):
	if dictionary:
		for item in sorted(dictionary):
			if item != root:
				b = dfp[item]['qmaPartID']
				c = item
				d = dfp[item]['qmaParentAssemblyID']
				print("%s (ParentID: %d, ChildID: %d)" % (b, c, d))
				print_dictionary(dictionary[item], item, level + 1)

def print_root(dictionary, root, level = 0.0):
	a = dfp[root]['qmaPartID']
	b = root
	c = dfp[root]['qmaParentAssemblyID']
	print("%s (ParentID: %d, ChildID: %d)" % (a, b, c))
	print_dictionary(dictionary, root)

print_root(items[0], 0)

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.