ProgrammingModerateTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
import itertools
print(list(itertools.islice(itertools.cycle('ab'), 5)), list(itertools.repeat(7, 2)))- A. ['a', 'b', 'a', 'b', 'a'] [7]
- B. ['a', 'b', 'a', 'b', 'b'] [7, 7]
- C. ['a', 'b', 'a', 'b'] [7, 7]
- D. ['a', 'b', 'a', 'b', 'a'] [7, 7]
Correct answer: D. ['a', 'b', 'a', 'b', 'a'] [7, 7]
cycle repeats the sequence forever, and islice takes five items. repeat(7, 2) yields 7 twice.
More Python Programming questions
- What is printed? python def f(): yield 1 yield 2 print(sum(f()), max(f()), list(zip(f(), f())))
- What is printed? python s = 'a-b-c' print(s.split('-', 1), s.rsplit('-', 1)[-1], s.partition('-')[2])
- What is printed? python print(divmod(-1, 10), divmod(1, -10), -1 % 10)
- What is printed? python words = ['hi', 'there', 'hey'] print(max(words), min(words, key=len), sorted(words, key=lambda w: (len(w), w)))
- What is printed? python print(pow(0, 0), 0 0 == 1, pow(2, -2, 5), pow(0, 0, 5))
- What is printed? python import math print(0.0 == -0.0, 1 / float('-inf'), 2 -1074 / 2 == 0, math.copysign(0.0, -1))