标签:完整 none http com one color 技术 ide 字符串
g = [i for i in range(30) if i % 3 == 0 ]#完整的列表推导式 print(g)
g = [i*i for i in range(30) if i % 3 == 0 ] print(g)
l =[[‘dsfdsa‘,‘husserhi‘,‘shdhfs‘,‘hfrues‘],[‘sdshfhsi‘,‘sgfygs‘,‘sdfsd‘]] trt = [name for i in l for name in i if name.count(‘s‘) == 2] print(trt)
只需要把中括号改为小括号就行。、
将一个key和value对调
d = {‘a‘:‘23‘,‘d‘:‘12‘} d_c = {d[k]:k for k in d} print(d_c)
d = {‘a‘:23,‘d‘:12,‘A‘:234,‘G‘:123} f = {k.lower():d.get(k.lower,0) + d.get(k.upper(),0) for k in d} print(f)
g = {l*l for l in [12,34,23,2,3,23,54,4,4,4,4,4,4]} print(g)
如果是列表推导式,则没有去重功能。会全部打印出来
标签:完整 none http com one color 技术 ide 字符串
原文地址:https://www.cnblogs.com/zly9527/p/11391957.html