L1 = ['Hello','World',19,'Apple',None] L2 = [i.lower() for i in L1 if isinstance(i,str)] print(L2)
两个关键点: 1、判断L1中的key是不是str,使用if语句和isinstance() 2、把L1中大写转换为小写,使用:x.lower()
Sign in to make a reply
快乐的杀马特
L1 = ['Hello','World',19,'Apple',None] L2 = [i.lower() for i in L1 if isinstance(i,str)] print(L2)
两个关键点: 1、判断L1中的key是不是str,使用if语句和isinstance() 2、把L1中大写转换为小写,使用:x.lower()