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?
#3
First question: what is a dictionary? A dictionary is a structure with name - value pairs. In your assignment it appears the keys are fixed. The keys must be: "Name, "sub1", "sub2" and "sub3".
So start easy. You already have a function to make a list of values. You only have to link these values to the keys. Like this:
ll = ["Arun", 75, 65, 82]
dd = {}
dd["Name"] = ll[0]
dd["sub1"] = ll[1]
dd["sub2"] = ll[2]
dd["sub3"] = ll[3]

print(dd)
Output:
{'Name': 'Arun', 'sub1': 75, 'sub2': 65, 'sub3': 82}
Now try to incorporate this in your program. When that works also look at the hint of Perfringo. His solution is more beautiful. But first try to make it work as simple as possible.
Reply


Messages In This Thread
RE: How can details be dynamically entered into a list and displayed using a dictionary? - by ibreeden - Mar-01-2020, 09:52 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,770 Feb-24-2022, 10:40 AM
Last Post: perfringo
  Loop through elements of list and include as value in the dictionary Rupini 3 2,742 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,938 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