Monday, July 23, 2018

Search in List

#!/usr/bin/python

mylist = []
mylist.append('one')
mylist.append('two')
mylist.append('three')
mylist.append('four')
mylist.append('five')

if ('three' in mylist):
   print ("Index of three is " + str(mylist.index('three')))
else:
   print ("three not present in mylist")

if ('nine' in mylist):
   print ("Index of nine is " + str(mylist.index('nine')))
else:
   print ("nine not present in mylist")

Python List - append and remove

#!/usr/bin/python

mylist = []
mylist.append("one")
mylist.append("two")
mylist.append("three")
mylist.append("four")
mylist.append("five")

print (mylist)
print ("=====================")

mylist.remove("five")
mylist.remove("one")
print (mylist)