Discuss / Python / 怎么得到输出结果['hello', 'world', 18, 'apple'],表达式应该怎么写求解

怎么得到输出结果['hello', 'world', 18, 'apple'],表达式应该怎么写求解

Topic source

ZakaryTime

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

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

8苍头__聪

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

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


  • 1

Reply