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?
#6
@Pranav - you code show basic confusion about use of function arguments.
Your functions take arguments, but in 2 out of 3 cases you are not using them properly.
Look at function Creat. It takes argument l (by the way poor choice of name for couple of reasons, but I will come to that at the end of my post). Then in the function body you don't use that l, you simply overvrite it in the list comprehension. When you call the function on line 18, you just pass empty list. The function will work all the same without any arguments.
def Creat():
    print("First value is a string then three comma separated integers\n")
    my_list =[str(x) for x in input().split(",")]
    return my_list
or even

def Creat():
    return [str(x) for x in input("First value is a string then three comma separated integers\n").split(",")]
same apply to argument d in your other function. In it however the use of l is correct - you pass argument and use it in the function.

Now, about other problems in your code
  • Don't use single letter names. Descriptive names are your friend and make it easier to maintain code in long-term.
  • If you use single letter for some reason, avoid names like l (lowercase L), o (lowercase O). It's difficult to distinguish lowercase L and 1 (one). Also lowercase O and zero. You can see it's difficult to tell if it is ll or l1
  • Avoid having multiple statements separated by ;. It's uncommon in python although syntax is valid.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: How can details be dynamically entered into a list and displayed using a dictionary? - by buran - Mar-02-2020, 10:17 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,717 Feb-24-2022, 10:40 AM
Last Post: perfringo
  Loop through elements of list and include as value in the dictionary Rupini 3 2,706 Jun-13-2020, 05:43 AM
Last Post: buran
  Fetch student details from a text file and print the details. Pranav 2 6,296 Mar-17-2020, 09:36 AM
Last Post: Pranav
  Functions returns content of dictionary as sorted list kyletremblay15 1 2,084 Nov-21-2019, 10:06 PM
Last Post: ichabod801
  Dictionary/List Homework ImLearningPython 22 10,795 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,674 Oct-24-2018, 06:40 PM
Last Post: LeSchakal
  Need some help with list and dictionary .txt GeekLife97 3 3,884 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