zoukankan      html  css  js  c++  java
  • 每日python(1)

    原始数据是每个用户对于所看过电影的评分:

    我们的用户有'Lisa Rose','Gene Seymour'等等,原始数据cirtics是一个字典,key为用户名,value为一个电影评分字典,该字典的key为电影名,value为评分

    如何找到所有的电影的集合呢?

     1 critics = {'Lisa Rose': {'Lady in the Water': 2.5, 'Snakes on a Plane': 3.5,
     2                          'Just My Luck': 3.0, 'Superman Returns': 3.5, 'You, Me and Dupree': 2.5,
     3                          'The Night Listener': 3.0},
     4            'Gene Seymour': {'Lady in the Water': 3.0, 'Snakes on a Plane': 3.5,
     5                             'Just My Luck': 1.5, 'Superman Returns': 5.0, 'The Night Listener': 3.0,
     6                             'You, Me and Dupree': 3.5},
     7            'Michael Phillips': {'Lady in the Water': 2.5, 'Snakes on a Plane': 3.0,
     8                                 'Superman Returns': 3.5, 'The Night Listener': 4.0},
     9            'Claudia Puig': {'Snakes on a Plane': 3.5, 'Just My Luck': 3.0,
    10                             'The Night Listener': 4.5, 'Superman Returns': 4.0,
    11                             'You, Me and Dupree': 2.5},
    12            'Mick LaSalle': {'Lady in the Water': 3.0, 'Snakes on a Plane': 4.0,
    13                             'Just My Luck': 2.0, 'Superman Returns': 3.0, 'The Night Listener': 3.0,
    14                             'You, Me and Dupree': 2.0},
    15            'Jack Matthews': {'Lady in the Water': 3.0, 'Snakes on a Plane': 4.0,
    16                              'The Night Listener': 3.0, 'Superman Returns': 5.0, 'You, Me and Dupree': 3.5},
    17            'Toby': {'Snakes on a Plane': 4.5, 'You, Me and Dupree': 1.0, 'Superman Returns': 4.0}}
    18 aa = [critics[i].keys() for i in critics]
    19 print aa
    20 bb = list(set(item for sublist in aa for item in sublist))
    21 print bb
  • 相关阅读:
    PTA 7-6 列出连通集(深搜+广搜)
    TZOJ 2648 小希的迷宫(并查集)
    HDU 3342 Legal or Not(拓扑排序)
    哈夫曼树
    mst
    [THUWC2017]随机二分图
    视察
    [bzoj3274]Circle
    [bzoj3273]liars
    求导相关
  • 原文地址:https://www.cnblogs.com/ivywenyuan/p/4734932.html
Copyright © 2011-2022 走看看