Chapter 8 – Python Dictionary Datatypes

Step 1
Open any text editor (gedit,pico,vi,nano) then enter the following python script and save the file with .py extension.
#Author : Jijo K Jose
print "\n————————————\nChapter 8 – Dictionaries\n————————————\n"
name = {'fname':'Jijo','mname':'K','lname':'Jose'}
print "\n", type(name)
print "\nDictonary Values : ", name
print "\nname['mname'] : " + name['mname']
print "\nAll keys -keys() : ", name.keys()
print "\nAll values -values() : ", name.values()
del name['mname']
print "\nDelete value del name['key'] : ", name
print "\nIterate through for loop items… -name.iteritems()\n"
for k,v in name.iteritems():
print k + "—->" + v
name['fname']= ['Jijo','Jibin','Jijan']
name['mname']= 'K'
name['lname']= 'Jose'
print "\nAdd more value to same key -name['fname']='value' : ", name
print "\n————————————\n"

Step 2
Change file permission to executable using chmod command.
Step 3
Execute the python file.

You can leave a response, or trackback from your own site.

Leave a Reply