We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Day 8: Dictionaries and Maps
Day 8: Dictionaries and Maps
Sort by
recency
|
2720 Discussions
|
Please Login in order to post a comment
n=int(input()) d={} for _ in range(n): details=input() f_name,phone_no=map(str,details.split()) d[f_name]=phone_no
while True: try: name=input() if name in d: print(f'{name}={d[name]}') else: print("Not found") except EOFError: break
public static void main(String []argh){ Scanner in = new Scanner(System.in); int n = in.nextInt(); Map phonebook=new HashMap<>(); for(int i = 0; i < n; i++){ String name = in.next(); int phone = in.nextInt(); phonebook.put(name,phone); // Write code here } while(in.hasNext()){ String s = in.next(); //write your code here if(phonebook.containsKey(s)) System.out.println(s+"="+phonebook.get(s)); else System.out.println("Not found"); } in.close(); }
Reading phonebook entries
Handling multiple queries safely until EOF
This is python solution can any one fix the error it failed test case1 n= int(input()) phonebook = {} for i in range(n):
queries = []
for i in range(n): query = input() queries.append(query)
for query in queries: if query in phonebook: print(f"{query}={phonebook[query]}")
Has anyone else had problems with test case 1 with C++? In the other test cases my code is fine
This is my code in case someone tells me my error.