Python Dictionary

Python dictionary is the key-value pair implementation in python. It is used to store and retrieve information using a key. It is also called associative array.

In the video below, I demonstrated how you can make use of dictionary to build a simple events management program.







The source code I used in this example are found below:

import sys
import re
print(sys.version)

print ('****mynew events****')
MyEvents={'Name':"Aware-IT.org Python Conference" , 'EventDate':'6/12/018' }
print (MyEvents)

###add Venue
print ('****mynew events with venue****')
MyEvents['Venue']= 'Makati Shangrila'
print (MyEvents)

###Change the venue
print ('****mynew events with updated venue****')
MyEvents['Venue']='Edsa Shangrila'
print (MyEvents)



###Add speakers
#print ('****mynew events with spekers****')
MyEvents['Speaker 1']='Luke Warm'
MyEvents['Speaker 2']='Baker Dozen'
MyEvents['Speaker 3']='Andy players'
print (MyEvents)
del MyEvents["Speaker 2"]
print (MyEvents)
#MyEvents.pop('Speaker 3')
#print (MyEvents)


MyEvents['Speaker 2']=MyEvents.pop('Speaker 3')
print (MyEvents)


print()
##print (MyEvents)
x=0
##print ('****Myevents printed horizontally****')
for key,values in MyEvents.items():
    print(key,":",values )
    if  (key[0:7])=="Speaker":
        x=x+1

        print()
print ("Total number of Speakers:",x)

print()
MyEvents['Participant 1']='Sarah Lance'
MyEvents['Participant 2']='Kara Danvers'
MyEvents['Participant 3']='Barry Allen'
MyEvents['Participant 4']='Oliver Queen'
MyEvents['Participant 5']='Laurel Lance'
#MyEvents['Participant 6']='Laurel Lance'

y=0
for key,values in MyEvents.items():
    print(key,":",values )#python3 , if in python2 use print item, instead.
    if  (key[0:11])=="Participant":
      y=y+1

print()
print ("Total number of PArticipants:",y)



Leave a Reply

Your email address will not be published. Required fields are marked *