Discuss / Python / 作业

作业

Topic source

小菘Barry

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

-- coding: utf-8 --

L1 = ['Hello', 'World', 18, 'Apple', None]

L2 = [i.lower() for i in L1 if isinstance(i, str)]

print(L2)

Ryan_CL

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

这样L2中会丢掉L1中的[18,None]这两个元素吧?

Rat_dh

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

期待输出: ['hello', 'world', 'apple'] 这样应该不用考虑18和None两个元素 List Comprehension应该不好实现都输出的情况


  • 1

Reply