-
[Dictionary] map key and value🐍 파이썬/파이썬 연습문제 2022. 7. 20. 09:11
문제: Implement a function that receives a list of Tuples, where every Tuple takes the form: (< Actor>,< Movie>,<Year>). The function should return two Dictionaries in a Tuple. The first dictionary should map from Actor to Movies, the second dictionary should map from Year to Movies.
Example
movie_maps( [("Keanu Reeves",Reeves","The Matrix", 1999 ),("Keanu Reeves", Bill Ted's Excellent Adventure", 1989)])
#({"Keanu Reeves":["The Matrix",Matrix","Bill Ted's Excellent Adventure"]}, { 1999 :["The Matrix"], 1989:["Bill Ted's Excellent Adventure"]})
def movie_maps(l): actor_dic = {} year_dic = {} for t in l: a, m, y = t if a not in actor_dic: actor_dic[a] =[] if y not in year_dic: year_dic[y] = [] actor_dic[a].append(m) year_dic[y].append(m) return actor_dic, year_dic
'🐍 파이썬 > 파이썬 연습문제' 카테고리의 다른 글
[Class] build a class that satisfies requirements (2) (0) 2022.07.27 [Class] build a class that satisfies requirements (1) (0) 2022.07.27 [list] find minimum in array (0) 2022.07.20 [modulo/devisor] sum up digit (0) 2022.07.18 [file] copy the file (0) 2022.07.17