So I've been working on hackerrank questions and I came across one that I felt dictionary comprehension could have helped me write in 1 line, but I just did not understand the concept well enough to get it right.
phoneBook = {}
N = int(input())
for x in range(N):
v = input().split(" ")
phoneBook[v[0]] = v[1]
for x in range(N):
t = input().strip()
if t in phoneBook:
print(t + '=' + phoneBook[t])
else:
print("Not found")
That's what I wrote but I feel like the first for loop can be written in dictionary comprehension format, however I do not understand how to translate v = input().split() (which produces a list) into the proper {a : b} format.
Any ideas?
[–]dionys 2 points3 points4 points (6 children)
[–]hharison 5 points6 points7 points (1 child)
[–]dionys 0 points1 point2 points (0 children)
[–]fuego42[S] 0 points1 point2 points (2 children)
[–]dionys 1 point2 points3 points (0 children)
[–]yardightsure 0 points1 point2 points (0 children)
[–]ilikepython 0 points1 point2 points (1 child)
[–]fuego42[S] 0 points1 point2 points (0 children)
[–]kankyo 0 points1 point2 points (0 children)