Answer to Question #298944 in Python for Rahul

Question #298944

Ayush is learning python programming. He has given some task to do on dictionary, but he don't know anything about dictionary but he is good in concepts of list. Your task is to write a python function Co-Dic(Y) function which takes a dictionary as input and convert it into list of list as shown in the example.

Ex1: Input- {1:'Arnab Goswami' , 2: 'Michael Stone', 3: 'Rajesh Mishra, 4:'Chris Jordan'}

Output - [ [1,'Arnab Goswami'],[2,'Michael Stone'],[3,'Rajesh Mishra'], [4,'Chris Jordan'] ]

2 . Input- {3.2: 214, 00.000: 25, 3: 'Man', 0.00: 31}

Output- [ [3.2,214], [0,31], [3,'Man'] ]


1
Expert's answer
2022-02-17T05:20:56-0500
def Co_Dic(Y):
    L = []
    for k in Y:
        L.append([k, Y[k]])
    return L


def main():
    print('Ex1:')
    Input = {1:'Arnab Goswami' , 2: 'Michael Stone', 3: 'Rajesh Mishra', 4:'Chris Jordan'}
    Output = Co_Dic(Input)
    print('Input -', Input)
    print('Output -', Output)

    print()
    print('Ex2:')
    Input = {3.2: 214, 00.000: 25, 3: 'Man', 0.00: 31}
    Output = Co_Dic(Input)
    print('Input -', Input)
    print('Output -', Output)


main()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS