#dictionary_example_1.py

import random
import sys
import os
##
## Python dictionaries are very similar to lists.
##
## lists:
##     my_list = [] creates an empty list
##     my_list = [ 1, 19, "school", 37, "John"]  creates a list with values in it
##     
##     With a list each item in the list is referred to with
##     an index number. 
##     
##     The first item in the list is my_list[0],  the last item is my_list[4].
##     The code To  add an item to end of a list is :  my_list.append( 42 )
##     To change the value of a list item the code is :  my_list[3] = "new value"
##
## See list_examples_2.py  for code using lists

# dictionaries:

dict_1 = {}  #creates an empty dictionary.  Note the use of "{" rather than "["
     
##     Dictionaries use Python variables, rather than integer numbers, in place
##     of an index.   Each item in the dictionary has a "key" (i.e. a Python
##     use like an index).

dict_1 = { "first":"Tommy", "last":"Green", "age": 21 }
            #creates a dictionary with values in it

dict_1["town"] = "Abingdon"   #dds an key & value pair to a list
     
print ("\n the dictionary value associated with the key ", \
       "\"first\" is ", dict_1["first"])
       #will print out the value associated with the key = "first"

dict_1["state"] = "Virginia"
     # adds a another key & value pair to the dictionary
     

all_key_list = list(dict_1.keys())
     #gives a list of all the keys used  by the dictionary
print("\n Keys used by dict_1 are : ", all_key_list )

all_key_vals = list(dict_1.values())
    #gives a list of all the values in the dictionary
print("\n Values in dictionary are : ",all_key_vals)

# a for loop can find each item in the list, but the order in which
# it finds them is unpredictable.

print("\nKey and variable pairs in dictionary\n")

for key_val in dict_1:
    print(key_val," : ", dict_1[key_val])

  
