在此插入代码
L1 = ['Hello', 'World', 18, 'Apple', None] L2 = [x.lower() for x in L1 if isinstance(x,str)] print(L2
好漂亮
这应该是出题人想要的答案
漂亮
为什么输出的结果不是['hello', 'world, 18, 'apple', None]
[s.lower() if isinstance(s,str) else s for s in L]、 我觉得这才是对的吧。。。
Sign in to make a reply
阳光明媚-M
L1 = ['Hello', 'World', 18, 'Apple', None] L2 = [x.lower() for x in L1 if isinstance(x,str)] print(L2