Skip to content

Instantly share code, notes, and snippets.

@dpwrussell
Last active December 24, 2015 17:19
Show Gist options
  • Save dpwrussell/6834384 to your computer and use it in GitHub Desktop.
Save dpwrussell/6834384 to your computer and use it in GitHub Desktop.
Dictionary of Dictionaries, for Tara.
dict1 = {'data1':'Lorem', 'data2':'ipsum', 'data3':'dolor'}
dict2 = {'data1':'sit', 'data2':'amet', 'data3':'consectetur'}
dict3 = {'data1':'adipisicing', 'data2':'elit', 'data3':'sed'}
#Basically just offically names each dictionary to the same as it's variable name,
dict_of_dict = {'dict1':dict1, 'dict2':dict2,'dict3':dict3}
# To find 'dict1_data2'
thing_to_find = 'dict1_data2'
s1,s2 = thing_to_find.split(r'_')
print 's1: ', s1 # s1 = 'dict1'
print 's2: ', s2 # s2 = 'data2'
print 'found: ', dict_of_dict[s1][s2]
# Dangerous insecure, computationally slower and much harder to debug when it goes wrong
# It may seem simpler, but it's to be avoided
print 'nasty: ', eval(s1)[s2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment