ASSIGNMENT OF DICTIONARY?
create a multi-dimension dictionary to store five student records and display max, min, total fees of students.
rno name branch fees
1001 xyz CS 45000
1002 abc IT 22000
The solution of This Program:-
stu = {'rno':[1001,1002],'sname':['manish','ramesh'],'branch':['CS','IT'],'fees':[45000,12000]}
for key in stu:
print(key,end=' ')
print()
for j in range(0,len(stu['rno'])):
print(str(stu['rno'][j])+" "+stu['sname'][j]+" "+stu['branch'][j]+" "+str(stu['fees'][j]))
Assignment of Dictionary Objects:-
WAP to convert a dictionary to set and set to the dictionary.
WAP to convert a dictionary to list and list to the dictionary.
WAP to create a multi-dimensions dictionary?
WAP to create a multi-dimension set?
Solution:-
stu = set({2,3,4,5,6,7}) # set to set, set to list, set to tuple, set to dict
for k in stu:
print(k)
WAP to convert Multi dimension Dictionary to Set?
The solution to this assignment:-
stu = {"a":{"a1":10,"a2":20},"b":{"b1":100,"b2":200}}
set1 = set()
set2 = set()
set3 = set()
for k in stu:
print(k)
set1.add(k)
for j in stu[k]:
print(j,stu[k][j])
set2.add(j)
set3.add(stu[k][j])
print(set1, set2, set3)
WAP to convert set to a tuple?
WAP to convert tuple to set?
WAP to convert set to list?
WAP to create Mark-sheet Program using Dictionary?
#convert dicitonary to list
ReplyDeletedict={'one':1,'two':2,'three':3,'four':4}
list1=[]
list2=[]
for i in dict:
list1.append(i)
list2.append(dict[i])
print(list1,list2)
#convert dicitonary to set
ReplyDeletedc={'one':1,'two':2,'three':3,'four':4}
s=set()
s1=set()
for i in dc:
s.add(i)
s1.add(dc[i])
print(s,s1)
#set to dictionary
ReplyDeletes={1,2,3,4,5,6,7}
d={k:'hi' for k in s}
print(d)
#list to dicitonary
ReplyDeletel=['one',12,'two',14,'three',14]
d={k:'a' for k in l}
print(d)
create two list one for key and another one for value
Delete#WAP to create a multi-dimensions dictionary?
ReplyDeletedata={'no':[1,2],'name':['a','b'],'post':[3,4],'salary':[20,40]}
for i in data:
print(i,end=' ')
print()
for j in range(0,len('no')):
print(str(data['no'][j])+' '+str(data['name'][j])+' '+str(data['post'][j])+' '+str(data['salary'][j]))
print()
#WAP to create a multi-dimension set?
ReplyDeletea = { {2, 4, 6, 8 }, {2, 3, 5, 7 }}
for i in range(len(a)) :
for j in range(len(a[i])) :
print(a[i][j], end=" ")
print()
doubt-error occur when run this program
a = { {2, 4, 6, 8 }, {2, 3, 5, 7 }}
TypeError: unhashable type: 'set'
>>>
#wap to convert set to a tuple
ReplyDeletes={'a',1,2,'b',40}
print("before conversion",s)
tup=tuple(s)
print("after conversion",tup)
#tuple to set
ReplyDeletetup=(1,2,3,'hi','hello')
a=type(tup)
print("before conversion",a,tup)
s=set(tup)
b=type(s)
print("after conversion",b,s)
#wap convert set to list
ReplyDeletes={'a',1,2,'c'}
l=[]
for i in s:
l.append(i)
print(l)
"""Q) WAP to Calculate Marksheet using five different subjects with the following condition.
ReplyDelete1) all subject marks should be 0 to 100.
3) if all subject marks are >=33 then percentage and division should be calculated.
4) if a student is suppl then five bonus marks can be applied to be pass and the result will be "pass by grace".
5) Display Grace Subject name, distinction subject name,suppl subject name, and failed subject name.
""""
dict={'phy':90,'che':40,'emg':89,'maths':29,'hindi':89}
count=0
gm=0
s=''
dist=''
for i in dict:
if dict[i]>=0 and dict[i]<=100:
print(dict[i])
if dict[i]<33:
count=count+1
s=s+i+ " "
gm=dict[i]
else:
if dict[i]>=75:
dist = dist+ i + " "
else:
print("All subject marks should be 0 to 100")
break
total=total+marks[i]
else:
if count==0 or(count==1 and gm>=29):
per= total/5
if per>33 and per<45:
print("Third division with {0} %".format(per))
elif per<60:
print("Second division with {0} %".format(per))
else:
print("First division with {0} %".format(per))
if gm>0:
print("You are pass by grace and grace marks is ",str(33-gm), "grace subject is ",s)
if dist!=0:
print("Distinction subject name is ",dist)
elif count==1:
print("suppl in ",s)
else:
print("fail in ",s)
#sir this program not run properly
#WAP to convert Multi dimension Dictionary to Set?
ReplyDeletes=set()
s1=set()
stu = {'rno':[1001,1002],'sname':['manish','ramesh'],'branch':['CS','IT'],'fees':[45000,12000]}
for key in stu:
s.add(key)
print(s)
for s1 in range(0,len(stu['rno'])):
print(str(stu['rno'][s1])+" "+stu['sname'][s1]+" "+stu['branch'][s1]+" "+str(stu['fees'][s1]))
#output of this program is
{'rno', 'fees', 'branch', 'sname'}
1001 manish CS 45000
1002 ramesh IT 12000
>>>not appropiate output come
Program to convert set to dictionary-->>
ReplyDeletes={"c","c++","vb",".net","php","python","java","testing"}
dic={y:"scs100" for y in s}
print(dic)
Program to convert dictionary to list-->>
ReplyDeletedic={'one':100,'two':99,'three':98,'four':97}
l1=[]
l2=[]
for i in dic:
l1.append(i)
l2.append(dic[i])
print(l1,l2)
Program to convert list to dictionary-->>
ReplyDeletel1=["a","b","c","d"]
l2=[324,361,400,441]
l=l1+l2
dic={k:"squares" for k in l}
print(dic)
DOUBT-->>Sir output should be like this-->>
{'a': 'squares', 'b': 'squares', 'c': 'squares', 'd': 'squares', 324: 'squares', 361: 'squares', 400: 'squares', 441: 'squares'}
Program to create multi dimension list-->>
ReplyDeletestu={'rollno.':[11,15],'sname':['suresh','ramesh'],'branch':['ec','mech'],'fees':[65000,66000]}
for key in stu:
print(key,end=' ')
print()
for j in range(0,len(stu['rollno.'])):
print(str(stu['rollno.'][j])+" "+stu['sname'][j]+" "+stu['branch'][j]+" "+str(stu['fees'][j]))
Program to create multi dimension set-->>
ReplyDeletestu=set((2,4,6,8,4,9))#set to set
for k in stu:
print(k)
Similarly
stu=set({2,4,6,8,4,9})#set to dictionary
stu=set([2,4,6,8,4,9])#set to list
stu=set((2,4,6,8,4,9))#set to tuple
Program to convert multi dimension dict to set-->>
ReplyDeletestu={"a":{"a1":101,"a2":201},"b":{"b1":999,"b2":998}}
set1=set()
set2=set()
set3=set()
for k in stu:
print(k)
set1.add(k)
for j in stu[k]:
print(j,stu[k][j])
set2.add(j)
set3.add(stu[k][j])
print(set1,set2,set3)
output-
a
a1 101
a2 201
b
b1 999
b2 998
{'a', 'b'} {'b1', 'b2', 'a1', 'a2'} {201, 101, 998, 999}
Program to convert set to tuple-->>
ReplyDeletes={2,54,"php","python","java","testing"}
t=tuple(s)
print(t)
output->('testing', 2, 54, 'java', 'php', 'python')
Program to convert tuple to set-->>
ReplyDeletet=("c","c++",111,222,78.90)
s=set(t)
print(s)
output->
{'c++', 78.9, 111, 'c', 222}
program to convert set to list-->>
ReplyDeletes={"dhoni","rohit","shubham",99}
l=list(s)
print(l)
# Multi dimension dictionary
ReplyDeletex = {"name":["Sunil","Anil"],"rno":[101,102], "branch":["cs","it"]}
for i in x:
print(i, end = ' ')
print()
for j in range(0,len(x["name"])):
print(str(x["name"][j]) + " " +str(x["rno"][j])+ " "+ str(x["branch"][j]))
#WAP to convert a dictionary to set and set to the dictionary.
ReplyDeletex = {"name":"Sunny","add":"Indore","number":12345}
a = set()
b= set()
for i in x:
a.add(i)
print(a)
for j in range(0,len(x["name"])):
b.add(x["name"])
b.add(x["add"])
b.add(x["number"])
print(b)
#WAP to convert set to a tuple?
ReplyDeletea = {245,58,69,64}
print(a,type(a))
y=tuple(a)
print(y,type(y))
#WAP to convert tuple to set?
ReplyDeletea = (23,"abc",65,89)
print(a,type(a))
z= set(a)
print(z,type(z))
#######################
b=set()
for i in a:
b.add(i)
print(b,type(b))
#WAP to convert set to list?
ReplyDeletea = {23,45,67,89}
print(a,type(a))
b= list(a)
print(b,type(b))
################################
c=[]
for i in a:
c.append(i)
print(c,type(c))
Post a Comment
If you have any doubt in programming or join online classes then you can contact us by comment .