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'] ]
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()
Comments
Leave a comment