Mar-01-2020, 05:43 AM
Please help me out with the below problem. It is mandatory for the input to be in the below format.
INPUT:
Enter number of dictionaries that you want to create
3
First value is a string then three comma separated integers
Arun,75,65,82
First value is a string then three comma separated integers
Ram,85,78,65
First value is a string then three comma separated integers
Shankar,98,85,82
My code is displaying the output in the below format.The key values in the below dict is the iterator.
SAMPLE TEST PROGRAM OUTPUT:
DESIRED TEST PROGRAM OUTPUT:
{Name: 'Arun', sub1: '75', sub2: '65', sub3: '82'}
{Name: 'Ram', sub1: '85', sub2: '78', sub3: '65'}
{Name: 'Shankar', sub1: '98', sub2: '85', sub3: '82'}
INPUT:
Enter number of dictionaries that you want to create
3
First value is a string then three comma separated integers
Arun,75,65,82
First value is a string then three comma separated integers
Ram,85,78,65
First value is a string then three comma separated integers
Shankar,98,85,82
My code is displaying the output in the below format.The key values in the below dict is the iterator.
SAMPLE TEST PROGRAM OUTPUT:
Output:{0: 'Arun', 1: '75', 2: '65', 3: '82'}
{0: 'Ram', 1: '85', 2: '78', 3: '65'}
{0: 'Shankar', 1: '98', 2: '85', 3: '82'}
Please help in modifying the code such that the output is displayed in the below format. The dictionary keys should be as below.DESIRED TEST PROGRAM OUTPUT:
{Name: 'Arun', sub1: '75', sub2: '65', sub3: '82'}
{Name: 'Ram', sub1: '85', sub2: '78', sub3: '65'}
{Name: 'Shankar', sub1: '98', sub2: '85', sub3: '82'}
a=int(input("Enter number of dictionaries that you want to create\n")) """Function to take the list values""" def Creat(l): print("First value is a string then three comma separated integers\n") l=[str(x) for x in input().split(",")] return l """Function to store list values in dictionary""" def Crd(l,d): d={} for i in range(4): kee=i val=l[i] d[kee]=val return d k=0 while(k<a): k=0 l1=[];l1=Creat(l1) d1={} d1=Crd(l1,d1) k+=1 if k==a: break l2=[];l2=Creat(l2) d2={} d2=Crd(l2,d2) k+=1 if k==a: break #As per the above process more lists and dictionaries can be created l3=[];l3=Creat(l3) ....... ....... z=0 while(z<a): z=0 print(d1) z+=1 if z==a:break print(d2) z+=1 if z==a:break #As per the above process the outputs of the dictionaries can be printed print(d3) ....... .......