Given an array and a target sum, find the sum of two numbers from the array equal to the target sum, and output the subscripts of these two numbers.

def two_sum():
    nums=[5,7,1,6,65,48,75,15,32,4,75]
    twosum=47
    for i,n in enumerate(nums):
        if twosum-n in nums:
            return i,nums.index(twosum-n)

print(two_sum())

Guess you like

Origin blog.csdn.net/qq_27900321/article/details/130237716