Q80240 - 2026编程挑战赛Python提高组40
统计题目( 单选题 )
下述代码运行结果正确的是:
from itertools import combinations
from functools import reduce
from bisect import bisect_left
from collections import Counter
nums = [1, 2, 2, 3]
# ① 统计所有长度为2的组合(不去重)
pairs = list(combinations(nums, 2))
# ② 计算 nums 的乘积
product = reduce(lambda x, y: x * y, nums)
# ③ 在有序数组中查找插入位置
pos = bisect_left(nums, 2)
# ④ 统计元素频次
cnt = Counter(nums)
print(len(pairs), product, pos, cnt[2])

关注我们