zoukankan      html  css  js  c++  java
  • python日记----2017.8.1

    内置函数:

    作业:

    3.用map来处理字符串列表,把列表中所有人都变成sb,比方alex_sb
    name = ['alex','wupeiqi','yuanhao','nezha']
    def ad(l):
    return l[:len(l)]+'_sb'
    print(list(map(ad, name)))
    ****************************************************************************
    4.用filter函数处理数字列表,将列表中所有的偶数筛选出来
    num = [1,2,3,4,5,6,7,8]
    def ou(num1):
    return num1 % 2 == 0
    print(list(filter(ou,num)))
    ****************************************************************************
    5.随意写一个20行以上的文件
    运行程序,先将内容读到内存中,用列表存储。
    接收用户输入页码,每页5条,仅输出当页的内容

    L=[]
    f = open('test','r',encoding='utf-8')
    L.append(f.read())
    a = L[0].split(' ')
    f.close()
    page = int(input('page>>').strip())
    print(a[page*5-5:page*5])
    for i in range(len(b)//5+1):

    ****************************************************************************

    # 6.如下,每个小字典的name对应股票名字,shares对应多少股,price对应股票的价格
    portfolio = [
    {'name': 'IBM', 'shares': 100, 'price': 91.1},
    {'name': 'AAPL', 'shares': 50, 'price': 543.22},
    {'name': 'FB', 'shares': 200, 'price': 21.09},
    {'name': 'HPQ', 'shares': 35, 'price': 31.75},
    {'name': 'YHOO', 'shares': 45, 'price': 16.35},
    {'name': 'ACME', 'shares': 75, 'price': 115.65}
    ]
    prices = [{"name":item["name"], "prices":item["shares"]*item["price"]} for item in portfolio]
    print(prices)
    #
    6.1.计算购买每支股票的总价
    L=[]
    for i in range(len(portfolio)):
    # print(i)
    print(portfolio[i]['name'],'总价%s'%(portfolio[i]['shares']*portfolio[i]['price']))
    L.append(portfolio[i]['price'])
    print(L)

    # 6.2.用filter过滤出,单价大于100的股票有哪些

    def money(qian):
    return qian > 100

    print(list(filter(money,L)))
  • 相关阅读:
    POJ 2251 Dungeon Master
    HDU 3085 Nightmare Ⅱ
    CodeForces 1060 B Maximum Sum of Digits
    HDU 1166 敌兵布阵(树状数组)
    HDOJ 2050 折线分割平面
    HDU 5879 Cure
    HDU 1878 欧拉回路
    HDU 6225 Little Boxes
    ZOJ 2971 Give Me the Number
    HDU 2680 Choose the best route
  • 原文地址:https://www.cnblogs.com/De-Luffy/p/7277136.html
Copyright © 2011-2022 走看看