$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #247

Which fix removes the bug?

line = 'red  green blue'
words = line.split(' ')
print(len(words))  # expected 3
  1. Use line.split(' ', 3)
  2. Use line.partition(' ')
  3. Call line.split() with no argument
  4. Call line.strip().split(' ')
split(' ') splits on every single space, so the double space yields an empty string. split() splits on runs of whitespace and drops empties.
Play Problem Solving ▸