Friday, September 23, 2011

Python String List

#!/usr/bin/python
#To print a list of numbers
print range(11)
numlist = range(5)
print "I am printing numlist populated by range method", numlist
print "Here I am printing values starting from 1st position",range(1,5)
print "Printing values starting from 1st position i+2",range(1,11,2)
strlist1 = ['Bala','subramaniam','Natarajan']
print "I am printing the string list1", strlist1
strlist1.reverse()
print "Reversing string list1", strlist1
strlist1.reverse()
strlist2 = ['Bala','Revathi']
print "I am printing the string list2", strlist2
strlist1.append(strlist2)
print "I am printing the appended string list1", strlist1
print strlist1[3][1]
strlist1.extend(strlist2)
print "I am printing the extended string list1", strlist1



#!/usr/bin/python
#To print a log_file
import string

log_file = "20110923 10.0.0.1 1110 192.168.1.1 80 404 vaka.html"
print log_file
print "The type of log_file is : ", type(log_file)
print string.split(log_file)
log_file2 = string.split(log_file)
print "The type of log_file2 is: ", type(log_file2)
print "The date in our log file is : ", log_file2[0]
log_file3 = string.join(log_file2)
print "The type of log_file3 is : ", type(log_file3)


No comments:

Post a Comment