标签:key lex code 逻辑 color 简单的 div bsp pre
列表生成式里可以加简单的逻辑,但是不能加太复杂的逻辑,这样会降低代码的可读性,会挨打的
names=[‘alex_sb‘,‘lqz_sb‘,‘yyh_sb‘,‘fm_sb‘,‘egon‘] res=[i+‘nb‘ for i in names] print(res)
字典生成式
keys=[‘name‘,‘age‘,‘sex‘] vals=[‘egon‘,18,‘male‘] dic={k:vals[i] for i,k in enumerate(vals)} print(dic) dic={k:vals[i] for i,k in enumerate(keys) if i > 0} print(dic)
标签:key lex code 逻辑 color 简单的 div bsp pre
原文地址:https://www.cnblogs.com/xufengnian/p/9941743.html