Skip to content

Instantly share code, notes, and snippets.

@maltzsama
Last active December 16, 2015 12:48
Show Gist options
  • Select an option

  • Save maltzsama/5436602 to your computer and use it in GitHub Desktop.

Select an option

Save maltzsama/5436602 to your computer and use it in GitHub Desktop.
Dictionary using pyton
#!/usr/bin/env python
#-*- coding:utf-8 -*-
#Definicion of {"YEAR":} dict
#"Value" of year is another dict
#So we have {"YEAR"":{}}
#another dict have:
#{
#"Key1":["VALUE1"],
#"Key2":["VALUE2"],
#"Key3": ["VALUE3"]
#}
yearDic = {"YEAR":
{
"First quarter:":["January", "February", "March", "April"],
"Second Quarter:":["May", "June", "July", "August"],
"Third Quarter:": ['September', 'October', 'November', 'December']
}
}
#First "for" to enumerate all Keys from yearDict.Keys()
for idx, yearKey in enumerate(yearDic.keys()):
#print avaliable keys and idx
print "%d %s: " %(idx, yearKey)
#get list of keys from internal dict
quartersList = yearDic.get(yearKey).keys()
#enumeration of keys
for i, quarter in enumerate(quartersList):
print " %d %s: "%(i, quarter)
quarterDic = yearDic.get(yearKey)
#print all elements in list
for quarterElement in quarterDic.get(quarter):
print " %s"%quarterElement
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment