Predict the output
What does this print?
words = ["flower", "flow", "flight"]
lo, hi = min(words), max(words)
i = 0
while i < len(lo) and lo[i] == hi[i]:
i += 1
print(lo, hi, lo[:i])Choose an answer, then open Show answer below to check it.
Show answer
Answer: A flight flower fl
Right: the smallest and largest words share 'fl', so every word does.
Only the two extreme words need comparing, since everything sorted between them shares at least their common start.
Why not the others?
- B flow flower flow. flight sorts before flow.
- C flight flow fl. flower sorts after flow because it is longer with the same start.