#591 · Lists · Intermediate · Find and fix · 65 XP · about 8 min
remove_short(words, min_length) should remove every word with fewer than min_length letters from the list words. It changes the caller's list in place (the same list object, not a new one) and returns how many words it removed. The words that stay keep their order.
The code in the editor has a bug. For ['to', 'be', 'or', 'not'] with min_length 3, the list should end up as ['not'], but 'be' survives, and the count comes out as 2 instead of 3.
words = ['apple', 'a', 'banana'] remove_short(words, 3) # returns 1 words # is now ['apple', 'banana'] words = ['to', 'be', 'or', 'not'] remove_short(words, 3) # returns 3 words # is now ['not']
words has 0 to 1,000 words.1 <= min_length <= 20First solves only, ranked by stars and then time.