ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
x = [i for i in range(3)] g = (i for i in range(3)) print(x == list(g), list(g), len(x))
- A. True [] 0
- B. True [] 3
- C. False [] 3
- D. True [0, 1, 2] 3
Correct answer: B. True [] 3
The generator is consumed by list(g) in the first comparison, so the second list(g) is empty. The list x equals [0, 1, 2], so the first check is True.
More Python Programming questions
- What is printed? python print(sorted(['b10', 'b9', 'a100'], key=lambda s: (s[0], int(s[1:]))))
- What is printed? python print(round(3.14159, 3), round(12345, -2), round(0.5), round(1.5), round(2.5, 0))
- What is printed? python a = [3, 1, 2] b = sorted(a, reverse=True)[:2] c = sorted(a)[-2:] print(b, c, sum(b) + sum(c))
- What is printed? python word = 'Level' print(word.lower() == word.lower()[::-1], word == word[::-1], word.casefold() == 'level')
- What is printed? python d = {} for w in ['b', 'a', 'b']: d[w] = d.get(w, 0) + 1 print(d, max(d, key=d.get), sorted(d.values()…
- Which is the time complexity of checking whether a string s of length n is a palindrome, using s == s[::-1]?