Wednesday, September 21, 2011

#!/usr/bin/python
#Author: Balasubramaniam Natarajan
#Date: 21-Sep-2011
#Purpose: lists

nlist = [1,2,3,4,5,6,7]
print "The value of nlist is", nlist
nlist.reverse()
print "The reversed value of nlist is", nlist
nlist.reverse()
print "The re-reversed value of nlist is", nlist

nlist2 = [8,9,10]
print "The value of nlist2 is: ", nlist2

nlist.append(nlist2)
print "The value of nlist.append(nlist2) is: ", nlist

print "The first value in nlist is: ", nlist[0]
print "The second value in nlist is: ", nlist[1]
print "The third value in nlist is: ", nlist[2]
print "The eight value in nlist is: ", nlist[7]
print "The eight value in nlist separately is: ", nlist[7][0]
print "The nineth value in nlist separately is: ", nlist[7][1]

#POP will behave similar to STACK Last In First Out
nlist.pop()
print "We poped out the last value of nlist", nlist

nlist.extend(nlist2)
print "We'v incorporated nlist2 elements in nlist", nlist
print "The eight value in nlist is: ", nlist[7]

nlist.pop()
print "We poped out the last value of nlist", nlist

#To get First In First Out we need to specify the number.
nlist.pop(0)
print "We poped out the first value of nlist", nlist

#To insert value in the nlist
nlist.insert(0,1)
print "We populate the first value of nlist", nlist

#END


No comments:

Post a Comment