i want my output to be [i, j] for which list[i] + list[j] equals to target value. for example;
nums=[2,7,11,15]
target=9
output=[0,1] as sum of num[0]+num[1]==target
i tried my code code as;
nums=[2,7,11,15] target=9 b=len(nums) for i,j in zip(range(b),range(b)): if nums[i]+nums[j]==target: print(i,j) i want to return position of element in list whose sums equals desired value, my above code does not ouput desired value, what will be best way to solve this problem?
https://stackoverflow.com/questions/66502434/using-two-variable-in-for-loop-for-list-operations March 06, 2021 at 12:39PM
没有评论:
发表评论