public
Created

Show materials - Python

  • Download Gist
gistfile1.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
def show_materials(materials, location):
""" show what's in the materials catalog """
key_superset = []
key_commonset = []
#
key = materials['key']
count = materials['count']
catalog = materials['materials']
if count != len(catalog):
# something not right
print "Expecting count to be same as length of catalog"
print "Failing..."
else: # good
print "Location: %s" % (location)
print " %s materials found" % (count)
for c in catalog:
keys = c.keys()
keys.sort()
# collect superset of all keys
for k in keys:
if k not in key_superset:
key_superset.append(k)
#
print " ", c['name']
if c['name'] == 'Cork':
print c['key'], c['weight'], c['thickness']
## if u'weight' in keys:
## print c['name']
## print " ", c
## #print " ",c['type']
## #print " ",c['kind']
## #print " ",c['updated_at']
## #print " ", keys
## if u'type' not in keys:
## print c['name']
## print " ", c
# Find common set of keys
key_commonset = deepcopy(key_superset)
for c in catalog:
keys = c.keys()
for k in key_commonset:
if k not in keys:
key_commonset.remove(k)
#
print "Superset of all keys found is:", key_superset
print "Common set of keys is:", key_commonset

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.