Created
April 22, 2014 19:20
-
-
Save pnf/11191107 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import chain,imap | |
manufacturing_groups = { 'multiglobal manufacturing group', | |
'intergalactic joint ventures', | |
'transdimensional megacorp', } | |
manufacturers = { 'multiglobal manufacturing group': { 'red heron manufacturers', | |
'blue bass super-corp', | |
'yellow dog llc', | |
'orange penguin family manufacturers', | |
'green hornet industries', }, | |
'intergalactic joint ventures': { 'yellow dog llc', | |
'purple butterfly inc', }, | |
'transdimensional megacorp': { 'maroon baboon manufacturer', | |
'orange penguin family manufacturers', | |
'green hornet industries', }, } | |
warehouses = { 'red heron manufacturers': {'neptune building'}, | |
'blue bass super-corp': {'saturn warehouse'}, | |
'yellow dog llc': {'mars storage'}, | |
'orange penguin family manufacturers': {'venus building'}, | |
'green hornet industries': {'jupiter building'}, | |
'purple butterfly inc': {'pluto ministorage'}, | |
'maroon baboon manufacturer': {'mercury warehouse'}, } | |
inventories = { 'neptune building': {'rose widgets', 'petunia widgets'}, | |
'saturn warehouse': {'rose widgets', 'daffodil widgets'}, | |
'mars storage': {'poppy widgets', 'forget-me-not widgets'}, | |
'venus building': {'goldenrod widgets'}, | |
'jupiter building': {'magnolia widgets'}, | |
'pluto ministorage': {'indian paintbrush widgets', 'daffodil widgets'}, | |
'mercury warehouse': {'carnation widgets'}, } | |
def flatmap(items, f): | |
return chain.from_iterable(imap(f, items)) | |
def getl(d): | |
return lambda k : d[k] | |
print set(flatmap(manufacturing_groups, getl(manufacturers))) | |
print set(flatmap(flatmap(manufacturing_groups,getl(manufacturers)),getl(warehouses))) | |
print set(reduce(flatmap, [manufacturing_groups, getl(manufacturers), getl(warehouses), getl(inventories)])) | |
def nest(l): | |
return map(lambda x : [x], l) | |
def getll(d): | |
def getlld(ks): | |
res = d[ks[0]] | |
return map(lambda x : [x] + ks, res) | |
return getlld | |
print list(reduce(flatmap, [nest(manufacturing_groups), getll(manufacturers), getll(warehouses), getll(inventories)])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment