zoukankan      html  css  js  c++  java
  • 列表解析练习题

     1 '''
     2 有两个列表,分别存放来老男孩报名学习linux和python课程的学生名字
     3 linux=['钢弹','小壁虎','小虎比','alex','wupeiqi','yuanhao']
     4 python=['dragon','钢弹','zhejiangF4','小虎比']
     5 '''
     6 # # 问题一:得出既报名linux又报名python的学生列表
     7 
     8 ## 常规方法
     9 # linux=['钢弹','小壁虎','小虎比','alex','wupeiqi','yuanhao']
    10 # python=['dragon','钢弹','zhejiangF4','小虎比']
    11 # l=[]
    12 # for i in linux:
    13 #     for j in python:
    14 #         if i==j:
    15 #             l.append(i)
    16 
    17 ## 列表解析处理
    18 # linux=['钢弹','小壁虎','小虎比','alex','wupeiqi','yuanhao']
    19 # python=['dragon','钢弹','zhejiangF4','小虎比']
    20 #
    21 # l = [i for i in linux for j in python if i == j]
    22 # print(l)
    23 
    24 # # 问题二:得出只报名linux,而没有报名python的学生列表
    25 
    26 # linux=['钢弹','小壁虎','小虎比','alex','wupeiqi','yuanhao']
    27 # python=['dragon','钢弹','zhejiangF4','小虎比']
    28 # l=[i for i in linux if i not in python]
    29 # print(l)
    30 
    31 # 问题三:得出只报名python,而没有报名linux的学生列表
    32 
    33 '''
    34 shares={
    35     'IBM':36.6,
    36     'lenovo':27.3,
    37     'huawei':40.3,
    38     'oldboy':3.2,
    39     'ocean':20.1
    40     }
    41 '''
    42 # # 问题一:得出股票价格大于30的股票名字列表
    43 # shares={
    44 #     'IBM':36.6,
    45 #     'lenovo':27.3,
    46 #     'huawei':40.3,
    47 #     'oldboy':3.2,
    48 #     'ocean':20.1
    49 #     }
    50 # s = [v for v in shares.values() if v > 30 ]
    51 # print(s)
    52 # # 问题二:求出所有股票的总价格
    53 #
    54 # l = [v for v in shares.values()]
    55 # print(sum(l))
    56 
    57 '''
    58 l=[10,2,3,4,5,6,7]
    59 得到一个新列表l1,新列表中每个元素是l中对应每个元素值的平方
    60 过滤出l1中大于40的值,然后求和
    61 '''
    62 # l=[10,2,3,4,5,6,7]
    63 # l1 = [ i**2 for i in l ]
    64 # 
    65 # l2 = [i for i in l1 if i > 40]
    66 # print(sum(l2))
    为什么要坚持,想一想当初!
  • 相关阅读:
    BZOJ 1391: [Ceoi2008]order
    BZOJ 4504: K个串
    2019 年百度之星·程序设计大赛
    POJ 2398 Toy Storage (二分 叉积)
    POJ 2318 TOYS (二分 叉积)
    HDU 6697 Closest Pair of Segments (计算几何 暴力)
    HDU 6695 Welcome Party (贪心)
    HDU 6693 Valentine's Day (概率)
    HDU 6590 Code (判断凸包相交)
    POJ 3805 Separate Points (判断凸包相交)
  • 原文地址:https://www.cnblogs.com/JerryZao/p/8799259.html
Copyright © 2011-2022 走看看