Create Dictionary Of Dict In Python By User Input Code Example


Example 1: create dictionary from input python


marks = {}

for i in range(10):
student_name = input("Enter student's name: ")
student_mark = input("Enter student's mark: ")
marks[student_name.title()] = student_mark

print(marks)

Example 2: 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]

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable