Testing extending a list I am learning Python. I have a scenario in my current project to benchmark the following code snippet; by using refactoring to increase the performance. Upon deployment my code will be used on a larger scale.
I'm trying from my side and am also looking for suggestions/guidance from you all. Is there a way to make this code much faster and cleaner with less line of code?
def test(x1, x2):
    if x2 is None:
        return
    elif len(x2) == 1:
        x1.append(x2)
        return
    else:
        for i in range(len(x2)):
            x1.append(x2[i])
    return

l = ['tt', 'yy', 'pp']
test(l, None)
print (l)


test(l, ['hello'])
print(l)

test(l, ['hello', 'world'])
print(l)
Use extend() instead of append() to add a list to another list, and use the fact that None and empty lists compare as False, while a non-empty list compares as True, and omit the redundant return statement:
def test(x1, x2):
    if x2:
        x1.extend(x2)

As for reducing the number of print statements, prepare a list or tuple with your test cases, and handle them all in a single for-loop:
l = ['tt', 'yy', 'pp']
testcases = [
    None,
    ['hello'],
    ['hello', 'world']
]

for testcase in testcases:
    test(l, testcase)
    print(l)