print("Hello to Data Structures")
In [2]:
pList1 = [1,'I am a boy']
print (pList1)
In [3]:
pInt =2
pReal =3.414
pString ="Praxis Business School "
pList2 =[pInt, pReal, pString, pList1]
print (pList2)
In [6]:
print ("member------")
print (pList2[0])
print (pList2[1])
print (pList2[2])
print (pList2[3])
print (pList2[3][0])
print (pList2[3][1])
In [7]:
#methods operation on list
print ("methods-----")
pList1.append(pInt)
print (pList1)
pList1.insert(1,pReal)
print (pList1)
pList1.remove (pReal)
print (pList1)
pList1.extend (pList2)
print (pList1)
In [11]:
#few more methods
print ("more methods")
print (pList1.count("I am a boy"),pList1.count(pInt))
print (pList1.index(pInt), pList1.index("I am a boy"))
pList1.reverse ()
print (pList1)
list1 = [10,12,9,11,7,6,5,14,40,20]
list1.sort ()
print (list1)
In [20]:
#list as a Stack
print ("stack......")
pStack =[12,20,10]
pStack.append(30)
print (pStack)
pPopped=pStack.pop ()
print (pPopped ,pStack)
#pPush=pStack.push (42)
#print (pPush)
In [3]:
#list as queue
print("Q -----")
from collections import deque
pList3 =["Ram","Shyam","Mohan"]
pQ= deque(pList3)
print (pQ)
a=pQ.pop()
print(a)
print (pQ)
b=pQ.pop()
print(b)
print (pQ)
pQ.append("Sita")
print (pQ)
In [43]:
#sets
print ("Sets.............")
pList5=["apple","mango","orange","apple","lemon"]
set2={"water lemon","graps","pineapple","Mango"}
print (pList5)
print (set2)
pSet =set(pList5)
print (pSet)
pSet1 = pSet.union(set2)
print (pSet1)
#pSet2= pSet.intersection(set2)
#print (pSet2)
In [49]:
#tuples
print ("Tuples........")
pTuple1 = 15,10,"Ram","Shyam"
print (pTuple1)
print (pTuple1[0],pTuple1[3])
pTuple2 = 20, "Praxis Business School", pTuple1
print(pTuple2)
In [67]:
# Dictionaries
print("Dictionaries ----------")
dTel = { "Ranjan": 1992, "Raushan" : 1985, "Rashmi" : 1988, "Gaurav" : 1980,"Gudiya" : 1994}
print(dTel)
print (dTel.keys())
print (dTel.values())
dTel ['Raj'] =1959
dTel ['Sobha']=1962
print (dTel)
dTel['Ranjan']=1990
print (dTel)
print ("Ranjan" in dTel)
print ("ranjan" in dTel)
In [70]:
#loop
print ("loop............")
for key, values in dTel.items():
print (key,values)
In [75]:
print("Enumerate .........")
for ix, val in enumerate (pList1):
print (ix,val)
for ix, val in enumerate (pTuple1):
print (ix,val)
for ix, val in enumerate (dTel):
print (ix,val)
In [78]:
print ("Zip........")
teachers = ["prithwis","charan","jaydeep","subhasis"]
subjects = ["bigdata", "communications", "stats", "datamining"]
for t, s in zip (teachers, subjects):
print (t, "teaches", s)
In [87]:
# Membership
print(pInt in pList2)
print(2 in pList2)
print(3.414 not in pList2)
fruit1 = ["apple", "pear", "orange", "mango"]
fruit2 = ["apple", "grape", "banana","mango"]
print ("grape" in fruit1)
print ("banana" in fruit2)
print (set(fruit1).intersection(fruit2))
print (set(fruit1).union(fruit2))
In [98]:
#delete
a= [-2,3,5,79,1,34,-7]
print (a)
a.sort()
print (a)
del a[0]
print (a)
#del a[6]
#print (a)
del a[2:4]
print (a)
del a[:]
print (a)