Treat functions that return multiple Python values

Asked

Viewed 166 times

0

For example, I have a function mergeSort(alist)that has return

return count, blist

i.e., returns an integer that is the inversion counter and a list of values.

When passing a list 5 4 3 1 2 5 and make print(mergeSort(lista)), is printed

(5, ['1', '2', '3', '4', '5']).

How to take only the whole (5) of the accountant?

1 answer

0


While writing the question occurred to me something very simple, I tested and it worked so I decided to continue the question and leave the answer in case someone has the same doubt.

Considering the example, just do

x, y = mergeSort(entrada)
    print(x)

And thus x receives the first return and y the second, and can be more variable according to the amount of returns of the function.

  • 1

    It’s called unpacking(desempacotar)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.