Python: Find the indices of two numbers that sum to 0 in a given list
Indices of Numbers Summing to Zero
Write a Python program to find the indices of two numbers that sum to 0 in a given list of numbers.
Input: [1, -4, 6, 7, 4] Output: [4, 1] Input: [1232, -20352, 12547, 12440, 741, 341, 525, 20352, 91, 20] Output: [1, 7]
Visual Presentation:

Sample Solution-1:
Python Code:
Sample Output:
Original List: [1, -4, 6, 7, 4] Indices of two numbers that sum to 0 in the said list: [4, 1] Original List: [1232, -20352, 12547, 12440, 741, 341, 525, 20352, 91, 20] Indices of two numbers that sum to 0 in the said list: [1, 7]
Flowchart:

For more Practice: Solve these Related Problems:
- Write a Python program to find the indices of two numbers in a list that sum to zero using a dictionary for lookup.
- Write a Python program to implement a two-pointer technique on a sorted list to detect two numbers whose sum is zero and return their indices.
- Write a Python program to search a list for a pair of numbers that add to zero without nested loops.
- Write a Python program to return the indices of two numbers summing to zero by iterating once and storing complements in a dictionary.
Sample Solution-2:
Python Code:
Sample Output:
Original List: [1, -4, 6, 7, 4] Indices of two numbers that sum to 0 in the said list: [1, 4] Original List: [1232, -20352, 12547, 12440, 741, 341, 525, 20352, 91, 20] Indices of two numbers that sum to 0 in the said list: [1, 7]
Flowchart:

Python Code Editor :
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Select a string from a given list of strings with the most unique characters.
Next: Find the list that has fewer total characters (including repetitions).
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics