Guest User

Untitled

a guest
May 22nd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. movie_sub_themes = {
  2. 'Epic': ['Ben Hur', 'Gone With the Wind', 'Lawrence of Arabia'],
  3. 'Spy': ['James Bond', 'Salt', 'Mission: Impossible'],
  4. 'Superhero': ['The Dark Knight Trilogy', 'Hancock, Superman'],
  5. 'Gangster': ['Gangs of New York', 'City of God', 'Reservoir Dogs'],
  6. 'Fairy Tale': ['Maleficent', 'Into the Woods', 'Jack the Giant Killer'],
  7. 'Romantic':['Casablanca', 'The English Patient', 'A Walk to Remember'],
  8. 'Epic Fantasy': ['Lord of the Rings', 'Chronicles of Narnia', 'Beowulf']}
  9.  
  10. movie_themes = {
  11. 'Action': ['Epic', 'Spy', 'Superhero'],
  12. 'Crime' : ['Gangster'],
  13. 'Fantasy' : ['Fairy Tale', 'Epic Fantasy'],
  14. 'Romance' : ['Romantic']}
  15.  
  16. themes_keys = movie_themes.keys()
  17. theme_movies_keys = movie_sub_themes.keys()
  18.  
  19. #Iterate in movie_themes
  20. #Check movie_themes keys in movie_sub_keys
  21. #if yes append the movie_sub_keys into the newdict
  22. newdict = {}
  23. for i in range(len(themes_keys)):
  24. a = []
  25. for j in range(len(movie_themes[themes_keys[i]])):
  26. try:
  27. if movie_themes[themes_keys[i]][j] in theme_movies_keys:
  28. a.append(movie_sub_themes[movie_themes[themes_keys[i]][j]])
  29. except:
  30. pass
  31. newdict[themes_keys[i]] = a
  32.  
  33. # newdict contains nested lists
  34. # Program to unpack the nested list into single list
  35. # Storing the value into theme_movies_data
  36. theme_movies_data = {}
  37. for k, v in newdict.iteritems():
  38. mylist_n = [j for i in v for j in i]
  39. theme_movies_data[k] = dict.fromkeys(mylist_n).keys()
  40.  
  41. print (theme_movies_data)
  42.  
  43. {'Action': ['Gone With the Wind', 'Ben Hur','Hancock, Superman','Mission: Impossible','James Bond','Lawrence of Arabia','Salt','The Dark Knight Trilogy'],
  44. 'Crime': ['City of God', 'Reservoir Dogs', 'Gangs of New York'],
  45. 'Fantasy': ['Jack the Giant Killer','Beowulf','Into the Woods','Maleficent','Lord of the Rings','Chronicles of Narnia'],
  46. 'Romance': ['The English Patient', 'A Walk to Remember', 'Casablanca']}
Add Comment
Please, Sign In to add comment