Python Forum
How can details be dynamically entered into a list and displayed using a dictionary?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can details be dynamically entered into a list and displayed using a dictionary?
#4
Thanks for your response. Your solution was simple and effective.
Below code is working fine.

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={}
    d["Name"] = l[0]; d["sub1"] = l[1]; d["sub2"] = l[2];d["sub3"] = l[3]
    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 
    
	..........
	..........	
 
z=0
while(z<a):
    z=0
    print(d1)
    z+=1
    if z==a:break
 
    print(d2)
    z+=1
    if z==a:break
 
	..........
	..........	
Reply


Messages In This Thread
RE: How can details be dynamically entered into a list and displayed using a dictionary? - by Pranav - Mar-02-2020, 06:05 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Program that allows to accept only 10 integers but loops if an odd number was entered gachicardo 4 3,769 Feb-24-2022, 10:40 AM
Last Post: perfringo
  Loop through elements of list and include as value in the dictionary Rupini 3 2,741 Jun-13-2020, 05:43 AM
Last Post: buran
  Fetch student details from a text file and print the details. Pranav 2 6,325 Mar-17-2020, 09:36 AM
Last Post: Pranav
  Functions returns content of dictionary as sorted list kyletremblay15 1 2,120 Nov-21-2019, 10:06 PM
Last Post: ichabod801
  Dictionary/List Homework ImLearningPython 22 10,935 Dec-17-2018, 12:12 AM
Last Post: ImLearningPython
  making a dictionary from a list, one key with multiple values in a list within a list rhai 4 3,716 Oct-24-2018, 06:40 PM
Last Post: LeSchakal
  Need some help with list and dictionary .txt GeekLife97 3 3,924 Jan-20-2017, 08:00 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020