Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#105·learn-python

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

Author: Imran-imtiaz48Created Jun 26, 2025Updated May 11, 2026

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:

python
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:

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

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

Source: trekhleb/learn-python

View original on GitHubView discussion on GitHub