Lecture 8
Lecture 8
Duplicates allowed, Duplicates allowed, Duplicates not allowed, Duplicate Key not
Size dynamic Size fix Size dynamic allowed, size dynamic
Print(t[0]) -> 10
Print (t[-1]) -> 30
Print(t[1:3]) -> 20,30
#wap to take a Tuple of Numbers from keyboard and
Print its Sum and Average?
t = eval(input(“enter tuple of numbers:”))
l = len(t)
Sum = 0
For x in t:
sum = sum +x
#add()
s.add(40) -> {0,1,3,4,40}
#update(x,y,z)
s.update(10,20,30)
Print(s) -> {0,1,3,4,30,10,20}
#wap to eliminate the duplicates from a list
● L = eval(input(“enter list of values:”))
● S = set(l)
● Print(s)
Dictionary
● d = {} or d = dict()
● d[100] = “ravi”
● d[200] = “rahul”
● d[300] = “amit”
D = eval(input(“Enter dictionary:”))
S = sum(d.values())
Print(“sum = “,s)
#Wap to check the number of occurrence of each
character.
word=input(“Enter any word”)
d={}
for x in word:
d[x]=d.get(x,0)+1