Is there a problem with python nesting two for loops?

title requirements:

given nums = [2,7,11,15], target = 9

because nums [0] + nums [1] = 2 + 7 = 9
, return index [0,1]

topic Source: sum Sum on leetcode

personal code

def twoSum(nums, target):
    l = []  -sharp 
    s = 0  -sharp 
    for _ in nums:
        i = 0
        s = s + 1
        p = nums.pop(0)
        l.append(p)
        for v in nums:
            if v == target - p:
                return [len(l) - 1, s + i]
            i = i + 1

personal thoughts and problems

my idea is to take an element into the external stack, record its value, and then traverse the elements that meet the criteria in the rest of the list.
s , I , in order to mark the sequence function of the elements that meet the requirements.
validation process found that every time I type

print(twoSum([1,3,3,5,2],7))

debugging results will show None , that is, when both numbers are at the end of the input list , None .

python novice, please give me more advice.

Oct.06,2021

come to the conclusion that the problem lies in the simultaneous use of for _ in nums: and nums.pop (0) . This will cause you to take a value for each iteration from a shrinking list. You can debugger or show _ of each loop to print , and you will find that you have jumped once in each loop.

incidentally, a solution: with the same complexity n ^ 2 but easy to understand

is given.
def twoSum(nums, target):
    for i in range(len(nums)):
        j = i + 1
        tmp = nums[i] + nums[j]
        if tmp == target:
            return [i, j]

print(twoSum([1,4,3,5,2],7))
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3ac86-2c24c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3ac86-2c24c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?