what is the solution of this by python 3 ?
Given an array of integers, return indices of the two numbers such that they add up to a spe
use itertools.combinations
which combines the elements of your list into non-repeated couples, and check if the sum matches. If it does, print the positions of the terms:
import itertools
integer_array = [2, 8, 4, 7, 9, 5, 1]
target = 10
for numbers in itertools.combinations(integer_array,2):
if sum(numbers) == target:
print([integer_array.index(number) for number in numbers])