David Grabovsky
David Grabovsky

Reputation: 13

Appending to 2 lists simultaneously

I have a piece of Python code that looks something like this:

array1 = []
array2 = []

def my_function():
    # do some stuff
    return x, y # both are integers

# append x to array1; append y to array2

What I'm trying to do is append the outputs of my_function to separate arrays. I understand that I need to somehow separate my_function's 2 outputs and then make 2 separate append() statements, but I'm not quite sure how to implement that.

Thanks in advance!

Upvotes: 0

Views: 90

Answers (1)

Ashoka Lella
Ashoka Lella

Reputation: 6729

x, y = my_function() #get x,y returned from my_function()
# append x to array1; append y to array2
array1.append(x)
array2.append(y)

Upvotes: 5

Related Questions