看了廖雪峰大拿的Python教程,在列表生成式章,产生了一个疑问
想将如下列表 L1 = ['Hello', 'World', 18, 'Apple', None]
通过大写转小写,非字符串去掉 原则 转换为 L2 == ['hello', 'world', 'apple']
正常的写法应该是:L2 = [s.lower() for s in L1 if isinstance(s,str) ]
但是若想通过 for前放置if else 方式应该怎么写?
L2 = [s.lower() if isinstance(s, str) else XXXXX for s in L1]
换句话说 列表生成式 if else 不返回值应该怎么写呢?