1,整理今天的博客,写课上代码,整理流程图。
2,用列表推导式做下列小题
(1) 过滤掉长度小于3的字符串列表,并将剩下的转换成大写字母
l = [‘abcd‘,‘ft‘,‘asd‘] l1 = [i.upper() for i in l if len(i) <3] print(l1)
(2) 求(x,y)其中x是0-5之间的偶数,y是0-5之间的奇数组成的元祖列表
l1 = [(x,y) for x in range(6) if x%2 is 1 for y in range(6) if y%2 is 0] print(l1)
(3) 求M中3,6,9组成的列表M = [[1,2,3],[4,5,6],[7,8,9]]
M = [[1,2,3],[4,5,6],[7,8,9]] l1 = [[x,y,z]for x in M[0] if x == 3 for y in M[1] if y ==6 for z in M[2]if z ==9] print(l1)
(4) 有以下数据类型:
x = {
‘name‘:‘alex‘,
‘Values‘:[{‘timestamp‘:1517991992.94,
‘values‘:100,},
{‘timestamp‘: 1517992000.94,
‘values‘: 200,},
{‘timestamp‘: 1517992014.94,
‘values‘: 300,},
{‘timestamp‘: 1517992744.94,
‘values‘: 350},
{‘timestamp‘: 1517992800.94,
‘values‘: 280}
],}
将上面的数据通过列表推导式转换成下面的类型:[[1517991992.94, 100], [1517992000.94, 200], [1517992014.94, 300], [1517992744.94, 350], [1517992800.94, 280]]
# l= [[j[‘timestamp‘],j[‘values‘]] for i in x.values() for j in i if i!=‘alex‘] # print(l)