Answer to Question #100904 in Python for Abiona

Question #100904
Create a Python dictionary that returns a list of values for each key. The key can be whatever type. Design the dictionary so that it could be useful for something meaningful. Create at least three different items in it.
1
Expert's answer
2020-01-02T11:25:48-0500

I created two versions, the first without keyboard input, and the second with keyboard input.


#version 1
dictionary = {"Bob": 16, "Mark": 15, "Elena": 17, "Tom": 13}

print("Age of my friends:\n")

for key in dictionary:
	print(key, "-" ,str(dictionary[key]), "y.o.")


#version 2
dictionary = {}
name = input("Enter dictionary name: ")
key = None
while True:
	key = input("Enter the key (0 if you want to finish filling): ")
	if key != "0":
		value = input("Enter the value: ")
		dictionary[key] = value
	else:
		break

print("\n" + name + ":\n")
for key in dictionary:
	print(key, "-" ,str(dictionary[key]))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS