Discuss / Python / 再简单的代码也要亲手敲一遍

再简单的代码也要亲手敲一遍

Topic source

翁岚敏

#1 Created at ... [Delete] [Delete and Lock User]

练习

-- coding:utf-8 --

L1 =['Hello','World',18,'Apple',None] L2 =[s.lower() for s in L1 if isinstance(s,str)] print(L2)

do_listcompr.py

!/usr/bin/env python3

-- coding:utf-8 --

print([xx for x in range(1,11)]) print([xx for x in range(1,11) if x % 2 == 0]) print([m + n for m in 'ABC' for n in 'XYZ'])

d ={'x':'A','y':'B','z':'C'} print([k + '=' + v for k,v in d.items()])

L = ['Hello', 'World', 'IBM', 'Apple'] print([s.lower() for s in L])


  • 1

Reply