天天看點

練習:請修改清單生成式,通過添加if語句保證清單生成式能正确地執行

#  -*- coding: utf-8 -*-
# L1 = ['Hello', 'World', 18, 'Apple', None]
# ----
# L2 = ???
# ----
# 期待輸出: ['hello', 'world', 'apple']
# print(L2)


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