learn-python icon indicating copy to clipboard operation
learn-python copied to clipboard

Typo in Variable Name: "weapon.strip()" Should Be "fruit.strip()" in List Comprehensions Example

Open Imran-imtiaz48 opened this issue 6 months ago • 0 comments

In the function test_list_comprehensions(), under the list comprehension that cleans up whitespace from a list of fruit names, the variable weapon is used instead of a more context-appropriate name such as fruit. This can be confusing for readers and may lead to misunderstandings, as the list is called fresh_fruit and contains fruit names.

Current code:

fresh_fruit = ['  banana', '  loganberry ', 'passion fruit  ']
clean_fresh_fruit = [weapon.strip() for weapon in fresh_fruit]
assert clean_fresh_fruit == ['banana', 'loganberry', 'passion fruit']

Suggested change: Change weapon to fruit for clarity and consistency:

clean_fresh_fruit = [fruit.strip() for fruit in fresh_fruit]

This will improve code readability and maintain consistency with the context of the example.

Imran-imtiaz48 avatar Jun 26 '25 19:06 Imran-imtiaz48