-1

Suppose we have a function abc where it returns four dicts after some processing as shown. For future if I will only need one tuple from the four, how to get it? Eg., I only want dict d_two which function abc returns or content of each of the four returns?

def abc():
    d_one = dict()
    d_two = dict()
    d_three = dict()
    d_four = dict()
    .
    .
    .
    .
    return (d_one, d_two, d_three, d_four)
mona
  • 1
  • 3
  • 1
    Just index the returned tuple `res = abc()[1]`. Also, your function returns one tuple containing 4 dicts, not 4 tuples. – NotAName Jul 04 '22 at 05:55
  • 1
    So, for one, these are dicts, not tuples. You return a single tuple with four dicts. And there is fat chance this is XY problem or there are problems with the implementation – buran Jul 04 '22 at 05:55

1 Answers1

0

You would need to deconstruct the returned value. There are multiple ways of doing this.

I should also note that dict() doesn't create tuples it creates dictionaries, but the process would be the same for both.

Here are some examples

_, d_two, _, _ = abc()

# or 

d_two = abc()[1]

# or

dicts = abc()
d_two = dicts[1]
Alexander
  • 16,091
  • 5
  • 13
  • 29