day14题目
day14作业及默写
1,整理今天所学内容,整理知识点,整理博客。
2,画好流程图。
3,都完成的做一下作业(下面题都是用内置函数或者和匿名函数结合做出):
4,用map来处理字符串列表,把列表中所有人都变成sb,比方alex_sb
name=['oldboy','alex','wusir']
5,用map来处理下述l,然后用list得到一个新的列表,列表中每个人的名字都是sb结尾
l=[{'name':'alex'},{'name':'y'}]
6,用filter来处理,得到股票价格大于20的股票名字
shares={
'IBM':36.6,
'Lenovo':23.2,
'oldboy':21.2,
'ocean':10.2,
}
7,有下面字典,得到购买每只股票的总价格,并放在一个迭代器中。
结果:list一下[9110.0, 27161.0,......]
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}]
8,还是上面的字典,用filter过滤出单价大于100的股票。
9,有下列三种数据类型,
l1 = [1,2,3,4,5,6]
l2 = ['oldboy','alex','wusir','太白','日天']
tu = ('**','***','****','*******')
写代码,最终得到的是(每个元祖第一个元素>2,第三个至少是4个)
[(3, 'wusir', ''), (4, '太白', '****')]这样的数据。
10,有如下数据类型:
lst1 = [ {'sales_volumn': 0},
{'sales_volumn': 108},
{'sales_volumn': 337},
{'sales_volumn': 475},
{'sales_volumn': 396},
{'sales_volumn': 172},
{'sales_volumn': 9},
{'sales_volumn': 58},
{'sales_volumn': 272},
{'sales_volumn': 456},
{'sales_volumn': 440},
{'sales_volumn': 239}]
将lst1按照列表中的每个字典的values大小进行排序,形成一个新的列表。
点击查看详细内容
4. name = ['oldboy','alex','wusir'] m = map(lambda x:x+'_sb',name) print(list(m))
l=[{'name':'alex'},{'name':'y'}]
m = map(lambda x:x['name']+'sb',l)
print(list(m))
shares={
'IBM':36.6,
'Lenovo':23.2,
'oldboy':21.2,
'ocean':10.2,
}f = filter(lambda x:shares[x]>20,shares)
dic = {i:shares[i] for i in f}
print(dic)
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}]m = map(lambda x:x['shares']*x['price'],portfolio)
print(list(m))
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}]
f = filter(lambda x:x['price']>100,portfolio)
print(list(f))
l1 = [1,2,3,4,5,6]
l2 = ['oldboy','alex','wusir','太白','日天']
tu = ('','','','****')m = map(lambda x,y,z:(x,y,z),l1,l2,tu) #s = zip(l1,l2,tu)也可以
f = filter(lambda x:x[0]>2 and x[2]>=''4,m)
print(list(f))
lst1 = [
{'sales_volumn': 0},
{'sales_volumn': 108},
{'sales_volumn': 337},
{'sales_volumn': 475},
{'sales_volumn': 396},
{'sales_volumn': 172},
{'sales_volumn': 9},
{'sales_volumn': 58},
{'sales_volumn': 272},
{'sales_volumn': 456},
{'sales_volumn': 440},
{'sales_volumn': 239},
]
s = sorted(lst1,key=lambda x:x['sales_volumn'])
print(list(s))