Skip to content

Merge List Appends Into Extend

Sourcery refactoring id: merge-list-appends-into-extend

Description:

Merge consecutive list appends into a single extend.

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:

my_list.extend([1, 2, 3, 4, 5, 6, 7, 8, 9])

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.