Merge List Extend
Documentation Index
Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt
Use this file to discover all available pages before exploring further.
Sourcery refactoring id: merge-list-extend
Section titled “Sourcery refactoring id: merge-list-extend”Description:
Section titled “Description:”Create the list with values instead of creating an empty list and extending it with another list
Before:
Section titled “Before:”hats_i_own = []hats_i_own.extend(["panama, baseball_cap, bowler"])After:
Section titled “After:”hats_i_own = ["panama", "baseball_cap", "bowler"]Explanation:
Section titled “Explanation:”When declaring a list with values it is much clearer to do so on one line rather than declaring an empty list and then extending it with values.