Answers for "how to get dictionary input from user in python"

1

user input dictionary python

# Creates key, value for dict based on user input
# Combine with loops to avoid manual repetition
class_list = dict() 
data = input('Enter name & score separated by ":" ') 
temp = data.split(':') class_list[temp[0]] = int(temp[1])  

OR

key = input("Enter key") 
value = input("Enter value") 
class_list[key] = [value]  
Posted by: Guest on May-26-2021
0

how to get dictionary input from user in python

# Creating nested dictionary with user input
family = {}
num = int(input("How many child dictionaries do you want to create: "))

for i in range(num):
    Member = input("Enter child dictionary name: ")
    family[Member] = {}
    Name = input("Enter person name: ")
    Age = input("Enter person age: ")
    family[Member]["Name"] = Name
    family[Member]["Age"] = Age

print("_" * 20)
for i in family:
    print("Name",":",family[i]["Name"])
    print("Age",":",family[i]["Age"])
    print("_" * 20)
Posted by: Guest on October-20-2021
0

how to get dictionary input from user in python

family = {}
num = int(input("How many elements?: "))
for i in range(num):
    k = input("Enter key: ")
    v = input("Enter value: ")
    family.update({k:v})
print(family)
Posted by: Guest on October-20-2021
0

how to get dictionary input from user in python

# Creating nested dictionary with user input
d = {}

d["Person1"] = {} # creating first child dictionary
d["Person2"] = {} # creating second child dictionary
d["Person3"] = {} # creating third child dictionary

d["Person1"]["Name"] = input("Enter person1 name: ")
d["Person1"]["Age"] = int(input("Enter person1 age: "))
d["Person1"]["Occupation"] = input("Enter person1 occupation: ")

d["Person2"]["Name"] = input("Enter person2 name: ")
d["Person2"]["Age"] = int(input("Enter person2 age: "))
d["Person2"]["Occupation"] = input("Enter person2 occupation: ")

d["Person3"]["Name"] = input("Enter person3 name: ")
d["Person3"]["Age"] = int(input("Enter person3 age: "))
d["Person3"]["Occupation"] = input("Enter person3 occupation: ")

print(d)
Posted by: Guest on October-20-2021
0

how to get dictionary input from user in python

family = {}
family["Name"] = input("Enter name: ")
family["Age"] = int(input("Enter age: ")) 
family["Relation"] = input("Enter relation: ")
print(family)
Posted by: Guest on October-20-2021
0

dictionary input from user in python3

d=dict(input().split() for x in range(n))
print(d)
Posted by: Guest on January-19-2021

Code answers related to "how to get dictionary input from user in python"

Python Answers by Framework

Browse Popular Code Answers by Language