首页 > 试题广场 >

在Python3中,下列选项中返回顺序列表lists=[1,

[不定项选择题]

在Python3中,下列选项中返回顺序列表lists=[1, 2, 3, 4, 5, 6, 7]中大于4的元素的是()

  • list(map(lambda x: x > 4, lists))

  • list(filter(lambda x: x > 4, lists))

  • [i for i in lists if i > 4]

  • lists[lists.index(4):]

A.lambda返回的是布尔值,map()函数直接返回的就是lambda函数作用到列表上的结果,所以最后返回的结果是布尔值列表[False, False, False, False, True, True, True]
B.filter()函数筛选出lambda函数的结果,返回的是[5, 6, 7]
C.明显是对的
D.lists.index(4)返回元素4在列表中的索引,是3。而lists[3:]从索引3开始截取列表,返回[4, 5, 6, 7],多了个4,错误
发表于 2025-03-10 17:14:34 回复(0)