Home > other >  Creating a dictionary with keys having lists
Creating a dictionary with keys having lists

Time:12-14

I need to create a dictionary of lists for the with 1 key having 5 values

{
  customer_id: [name, date of birth, location, phone number, age]
}

How can I do that by taking input during runtime? How to store a date as a value in a dictionary

CodePudding user response:

The following code will help you:

d={}
customer_id=int(input())
l=[]
name=input()
date of birth=input()
location=input()
phone=input()
age=input()
l.append(name) 
l.append(date of birth) 
l.append(location) 
l.append(phone) 
l.append(age) 
d[customer_id]=l

Keep in mind that name, date of birth, location, phone and age, all will be treated as a string.

  • Related