# File: moWeDicts.py # Author: Dr. Gibson # Date: 11/7/2016 # Section: N/A # E-mail: k.gibson@umbc.edu # Description: # This file contains python code that creates a dictionary # from two lists, and performs some other operations as well. def main(): names = ["Tina", "Pratik", "Amber"] major = ["Social Work", "Pre-Med", "Art"] # start with an empty dictionary naMaj = {} # iterate over the INDEXES so we can look at both lists at once for i in range(len(names)): # naMaj [key] = value naMaj[ names[i] ] = major[i] # some info about the dictionary print("Printing the dictionary:", naMaj) print("Length of the dictionary:", len(naMaj)) print() # look for Amber and Nathan's major print("Amber's major:", naMaj.get("Amber")) print("Nathan's major:", naMaj.get("Nathan")) print() print("You can nest dictionaries, but why?") terribleIdea = {"WHY?" : naMaj} print(terribleIdea) main()