ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
values = [0, 1, 2, 3] print([v for v in values if v] == values[1:], any(values), all(values[1:]))
- A. True True True
- B. False True False
- C. True False True
- D. True True False
Correct answer: A. True True True
Filtering out the falsy 0 leaves [1, 2, 3], which equals values[1:]. any is True because some value is nonzero. all is True because every value after index 0 is nonzero.
More Python Programming questions
- What is printed? python import heapq nums = [7, 2, 9] heapq.heapify(nums) print(nums[0], heapq.nlargest(1, nums)[0], heapq.nsmallest(2…
- What is printed? python print(any(x > 3 for x in range(10)), next(x for x in range(10) if x x > 20), sum(x for x in range(0, 10, 4)))
- What is printed? python s = '12:34:56' h, m, sec = map(int, s.split(':')) print(h 3600 + m 60 + sec, divmod(h 3600 + m 60 + sec, 60))
- What is printed? python print([x % 3 for x in [-7, -3, 0, 4]])
- What is printed? python def counter(): count = 0 def step(): nonlocal count count += 2 return count return step c1 = counter() c2 =…
- What is printed? python values = {'x': [1, 2], 'y': [3]} total = sum(len(v) for v in values.values()) keys = sorted(values, key=lambda k…