Last active
December 16, 2015 12:48
-
-
Save maltzsama/5436602 to your computer and use it in GitHub Desktop.
Dictionary using pyton
This file contains hidden or 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
| #!/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