Assignment On List
Assignment On List
t=[1,2,7,56,89,66,78,0]
print t
print "maximum is:",max(t)
print "minimum is:",min(t)
3.Write a program to find the position of maximum and minimum element’s position in a
list.
l=[2,6,12,3,56,8,9,22]
m=max(l)
print m
print l.index(m)
m1=min(l)
print m1
print l.index(m1)
4.Write a program to print all the elements in a list that are greater than a given value.
l= [21,7,8,90,33,50]
print(l)
print( s)
l=[2,6,12,3,56,1,5]
l1=[10,2,3,56,123]
print l
print l1
for i in l:
for j in l1:
if i==j:
print i
l1=[10,2,3,56,123]
leng = len(l1)
print l1
print leng
import random
l=[]
for i in range(1,10):
x=random.randint(10,30)
l.append(x)
print l
10. Write a program to split the even and odd elements into 2 different lists.
l=[1,3,45,7,6,78,55,44,86,52,33]
print (l)
print ("even=",even)
print ("odd=",odd)
d1={"sunita":3,"ryna":5,"ziva":7}
print dict(d1)
12. Write a program to create a phone directory for all your friends and then print it.
d={'priyanka':8769429955,'iti':5389900689,'sikha':77503654891}
print (d)
13.Marks of three students ‘Suniti’, ‘Ryna’, and ‘Ziva’ in 3 subjects are available in
dictionary.
Output:
Key Value
Subject(Key) Marks(Value)
1 40
2 50
3 60
D4 = {'Sunita':D1,'Ryna':D2,'Ziva':D3}
print D4
for i in D4:
print "Ryna:"
for j in D1:
print "Sunita:"
for j in D2:
print "Ziva:"
for j in D2:
14 Create a dictionary whose keys are month names and whose values are the number
of days in the corresponding months.
a) Ask the user to enter a month name and use the dictionary to tell them how
many days are in the month.
b) Print out all of the keys in alphabetical order.
c) Print out the (key value) pairs started by the number of days in each month.
Calendar2018 = {'january' : 31,'february' : 28,'march' : 31,'april' : 30,'may' : 31,'june' : 30,'july' : 31,'august' : 31,
monthName=monthName.lower()
if monthName in Calendar2018:
else:
sortedkeys = sorted(Calendar2018)
for i in sortedkeys:
print i
print"\nThe (key-value) pairs sorted by the number of days in each month are as under.\n"
for i in range(len(sortedByValues)):
print sortedByValues[i]