I am trying to return a dictionary through a function shown in the code using jupyter notebooks. I am a beginner in Python and not sure how to go about this but I feel the answer is trivial.In my code when i run it, i get {}.
Im not sure if a for loop or if statement is needed.
def build_book_dict(titles, pages, firsts, lasts, locations):
if True:
return dict()
else:
None
titles = ["Harry Potter", "Fear and Lothing in Las Vegas"]
pages = [200, 350]
firsts = ["J.K.", "Hunter"]
lasts = ["Rowling", "Thompson"]
locations = ["NYC", "Aspen"]
book_dict = build_book_dict(titles, pages, firsts, lasts, locations)
print (book_dict)
result should be -->
{'Fear and Lothing in Las Vegas': {'Publisher': {'Location': 'Aspen'},
'Author': {'Last': 'Thompson', 'First': 'Hunter'}, 'Pages': 350},
'Harry Potter': {'Publisher': {'Location': 'NYC'},
'Author': {'Last': 'Rowling', 'First': 'J.K.'}, 'Pages': 200}}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…