-3

My program is :

def question_fourth_solution(array_nums):
    odd_len = len(list(filter(lambda x: (x%2 != 0),array_nums)))
    even_len = len(list(filter(lambda x: (x%2 == 0),array_nums)))
    print(odd_len,even_len)
    return array_nums

question_fourth_solution([1, 2, 3, 5, 7, 8, 9, 10])

I want my output in tuple form like given below: (5,3)

Saurabh G
  • 19
  • 2
  • 8

1 Answers1

3

You may simply return the two results using return odd_len, even_len, which automatically returns them as a tuple equivalent to return (odd_len, even_len), and print the return value of the function:

def question_fourth_solution(array_nums):
    odd_len = len(list(filter(lambda x: (x % 2 != 0), array_nums)))
    even_len = len(list(filter(lambda x: (x % 2 == 0), array_nums)))
    return odd_len, even_len

print(question_fourth_solution([1, 2, 3, 5, 7, 8, 9, 10]))

Outputs:

(5, 3)

Inside your function, if you wanted to print the result as a tuple, you could do this using:

print((odd_len, even_len))
dspencer
  • 4,297
  • 4
  • 22
  • 43