How to import data form lists in a dictionary in Python?

Question:

I want to create a program that takes 3 different inputs and stores them in 3 separate lists and then be able to combine them in a dictionary and print on screen.

So far I got this :

size = input("Enter size of family: ")
names = []
year = []
address= []
for i in range(int(size)):
    print("Enter name: ", end=' ')
    names.append(input())
    print("Enter birthyear: ", end=' ')
    year.append(int(input()))
    print("Enter address: ", end=' ')
    address.append(str(input()))

d = list(zip(names, year, address))
print(d)
Asked By: Alexander Atanasov

||

Answers:

You can simplify this code quite a bit:

size = int(input("Enter size of family: "))
family_data = {}

for i in range(size):
    name = input("Enter name: ")
    birthyear = int(input("Enter birthyear: "))
    address = input("Enter address: ")

    family_data[name] = {'birthyear': birthyear, 'address': address}

print(family_data)
Answered By: NYC Coder
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.