def twoSum(nums, target):
nums_index = [(v, index) for index, v in enumerate(nums)]
nums_index.sort()
begin, end = 0, len(nums) - 1
while begin < end:
curr = nums_index[begin][0] + nums_index[end][0]
if curr == target:
return [nums_index[begin][1], nums_index[end][1]]
elif curr < target:
begin += 1
else:
end -= 1
nums = [4,2,5,2,3,7,4,8]
target = 6
twoSum(nums, target)
Now, let’s try to run this code here in the browser using Pyscript and repl. Just copy, paste the code into interactive Python repl and press the green button.