Merge List Appends Into 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-appends-into-extend
Section titled “Sourcery refactoring id: merge-list-appends-into-extend”Description:
Section titled “Description:”Merge consecutive list appends into a single extend.
Before:
Section titled “Before:”my_list.extend([1, 2])my_list.append(3)my_list.append(4)my_list.extend((5, 6, 7))my_list.append(8)my_list.append(9)After:
Section titled “After:”my_list.extend([1, 2, 3, 4, 5, 6, 7, 8, 9])Explanation:
Section titled “Explanation:”When adding multiple items to a list, it is cleaner to combine consecutive calls
to list.append or list.extend into a single list.extend when possible.