ProgrammingHardTCS NQT · Wipro pattern
Which statement about dictionary iteration order in Python 3.7 and later is correct?
- A. Iteration follows sorted key order
- B. Iteration order changes between runs
- C. Only integer keys keep their insertion order
- D. Iteration follows insertion order
Correct answer: D. Iteration follows insertion order
Dicts keep the order in which keys were first inserted, a guarantee since Python 3.7. Sorting, hash randomisation and key type do not change this.
More Python Programming questions
- What is printed? python class Q: def init(self): self.i, self.o = [], [] def push(self, x): self.i.append(x) def pop(self): if not self.o…
- What is printed? python print([y for x in [[1, 2], [3], []] for y in x if y % 2])
- What is printed? python out = [] for i in range(3): try: if i == 1: continue out.append(i) finally: out.append('f') print(out)
- What is printed? python print(int('0x1f', 16), int('1f', 16), int('0o17', 8))
- What is printed? python print(divmod(-9, 4), -9 % 4, round(-9 / 4))
- What is printed? python print(len(str(float(1016))), str(1016 1.0), len(str(1016)))