Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

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 dictionary?  means create a dictionary under a set

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?





27 Comments

If you have any doubt in programming or join online classes then you can contact us by comment .

  1. #convert dicitonary to list
    dict={'one':1,'two':2,'three':3,'four':4}
    list1=[]
    list2=[]
    for i in dict:
    list1.append(i)
    list2.append(dict[i])
    print(list1,list2)

    ReplyDelete
  2. #convert dicitonary to set
    dc={'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)

    ReplyDelete
  3. #set to dictionary
    s={1,2,3,4,5,6,7}
    d={k:'hi' for k in s}
    print(d)

    ReplyDelete
  4. #list to dicitonary
    l=['one',12,'two',14,'three',14]
    d={k:'a' for k in l}
    print(d)

    ReplyDelete
  5. #WAP to create a multi-dimensions dictionary?
    data={'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()

    ReplyDelete
  6. #WAP to create a multi-dimension set?
    a = { {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'
    >>>

    ReplyDelete
  7. #wap to convert set to a tuple
    s={'a',1,2,'b',40}

    print("before conversion",s)
    tup=tuple(s)

    print("after conversion",tup)

    ReplyDelete
  8. #tuple to set
    tup=(1,2,3,'hi','hello')
    a=type(tup)
    print("before conversion",a,tup)
    s=set(tup)
    b=type(s)
    print("after conversion",b,s)

    ReplyDelete
  9. #wap convert set to list
    s={'a',1,2,'c'}
    l=[]
    for i in s:
    l.append(i)
    print(l)

    ReplyDelete
  10. """Q) WAP to Calculate Marksheet using five different subjects with the following condition.
    1) 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

    ReplyDelete
  11. #WAP to convert Multi dimension Dictionary to Set?
    s=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

    ReplyDelete
  12. Program to convert set to dictionary-->>

    s={"c","c++","vb",".net","php","python","java","testing"}
    dic={y:"scs100" for y in s}
    print(dic)

    ReplyDelete
  13. Program to convert dictionary to list-->>

    dic={'one':100,'two':99,'three':98,'four':97}
    l1=[]
    l2=[]
    for i in dic:
    l1.append(i)
    l2.append(dic[i])
    print(l1,l2)

    ReplyDelete
  14. Program to convert list to dictionary-->>

    l1=["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'}

    ReplyDelete
  15. Program to create multi dimension list-->>


    stu={'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]))

    ReplyDelete
  16. Program to create multi dimension set-->>

    stu=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

    ReplyDelete
  17. Program to convert multi dimension dict to set-->>

    stu={"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}

    ReplyDelete
  18. Program to convert set to tuple-->>

    s={2,54,"php","python","java","testing"}

    t=tuple(s)
    print(t)

    output->('testing', 2, 54, 'java', 'php', 'python')

    ReplyDelete
  19. Program to convert tuple to set-->>

    t=("c","c++",111,222,78.90)
    s=set(t)

    print(s)

    output->
    {'c++', 78.9, 111, 'c', 222}

    ReplyDelete
  20. program to convert set to list-->>

    s={"dhoni","rohit","shubham",99}
    l=list(s)
    print(l)

    ReplyDelete
  21. # Multi dimension dictionary
    x = {"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]))

    ReplyDelete
  22. #WAP to convert a dictionary to set and set to the dictionary.
    x = {"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)


    ReplyDelete
  23. #WAP to convert set to a tuple?
    a = {245,58,69,64}
    print(a,type(a))
    y=tuple(a)
    print(y,type(y))

    ReplyDelete
  24. #WAP to convert tuple to set?
    a = (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))

    ReplyDelete
  25. #WAP to convert set to list?
    a = {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))

    ReplyDelete



  26. # Program for Multi-Dimension Dictionary to Store Student Records and Display Max, Min, Total Fees of Students.

    Student = dict()
    ids = int(input("How many Student Entries you want to add:-\t"))

    # Adding new Students

    for j in range(0, ids):
    i = input("Enter the Roll No. of Student :-")

    Student[i] = {}
    # Adding NAME of Student
    Student[i]['Name'] = str(input("Enter the name of Student :-")).upper()
    # Adding Branch of Student
    Student[i][' Branch'] = str(input("Enter the Branch of Student:-")).upper()
    # Adding Fee of Student
    Student[i]['Fee'] = int(input("Enter the Fee of Student :-"))

    lst = Student.items()

    res = sorted(Student.items(), key = lambda x: x[1]['Fee'])
    print(res)

    i = input("Enter the Roll No. of Student :-")

    if i in Student:
    print("\n",Student[i])
    else:
    print("Wrong Roll No.")

    ReplyDelete

Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post