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
  • 相关阅读:
    flex布局
    input框不能输入问题
    JS的innerHTML完成注册表
    CSS的z-index属性和box-shadow属性
    JS个人笔记
    css照片墙
    透明度设置
    a标签的name属性
    iframe标签
    title属性
  • 原文地址:https://www.cnblogs.com/ivywenyuan/p/4734932.html
Copyright © 2011-2022 走看看