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
  • 相关阅读:
    给微信小程序添加简单小动画
    微信小程序封装wx.request方法
    微信小程序项目,实现图书列表渲染,以及图书详情跳转
    总结一下微信小程序中父子兄弟组件传递数据
    给自己看的flex布局方法
    moment.js踩坑
    Vue项目的一些优化策略
    vue中按需使用第三方插件
    js基础复习2,class和原型
    js基础复习1
  • 原文地址:https://www.cnblogs.com/ivywenyuan/p/4734932.html
Copyright © 2011-2022 走看看