方案一:
L1 = ['Hello', 'World', 18, 'Apple', None] L2 = [s.lower()for s in L1 if isinstance(s,str)] print (L2)
方案二:
L1 = ['Hello', 'World', 18, 'Apple', None] L2 = [] for i in L1: if isinstance(i,str): L2.append(i) else: pass L3 = [s.lower() for s in L2] print (L3)
我就用的第二个,好复杂,觉得大家好聪明啊都能想到第一个那么简洁的。。。看到差距拉~~~
Sign in to make a reply
遗弃之城
方案一:
方案二: