Tuesday, August 19, 2014

Dictionary Accessing


Dictionary Accessing 

Jython provides many sequqnces and datastructures. Here is a map type where it is a combination of key and value pair or elements in a list.

Diectonary in Jython script
Lets do the experiment with Dictonary objects in Jython.
Example of Dicttionary objects in Jython


#This script is for adding, deleting, modifying,itrating.

D={'dmgr':'10.12.13.14:80','app1':'10.0.0.12:90','app2':'10.0.0.15:100'}

#Adding a element to dictionary D.

D['app3']='10.1.1.12:85'
#Update with New dictionary
D2={'app4':'10.0.0.0:95'}
D.update(D2)
for k,v in D.items(): print k,'->',v

#modifying dictionary element

print 'modifying the dictionary app2'

D['app2']='10.0.0.15:98'
for k,v in D.items(): print k,'->',v

keylist=D.keys()

k=keylist.sort()

print keylist

for k in keylist: print k,'->',D[k]


O/P

wsadmin>execfile('/home/krish/jython/dict.acc.py')
app4 -> 10.0.0.0:95
dmgr -> 10.12.13.14:80
app3 -> 10.1.1.12:85
app2 -> 10.0.0.15:100
app1 -> 10.0.0.12:90
modifying the dictionary app2
app4 -> 10.0.0.0:95
dmgr -> 10.12.13.14:80
app3 -> 10.1.1.12:85
app2 -> 10.0.0.15:98
app1 -> 10.0.0.12:90
['app1', 'app2', 'app3', 'app4', 'dmgr']
app1 -> 10.0.0.12:90
app2 -> 10.0.0.15:98
app3 -> 10.1.1.12:85
app4 -> 10.0.0.0:95
dmgr -> 10.12.13.14:80


No comments:

Post a Comment

Containerization with Docker

Containerization with Docker
Learn modern microservices containers grow