- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program to get indices of sign change in a list
When it is required to get indices of sign change in a list, a simple iteration along with ‘append’ method can be used.
Below is a demonstration of the same
my_list = [71, 24, -34, -25, -76, 87, 29, -60, 70, 8] print("The list is :") print(my_list) my_result =  for index in range(0, len(my_list) - 1): if my_list[index] > 0 and my_list[index + 1] < 0 or my_list[index] < 0 and my_list[index + 1] < 0: my_result.append(index) print("The result is :") print(my_result)
The list is : [71, 24, -34, -25, -76, 87, 29, -60, 70, 8] The result is : [1, 2, 3, 6]
A list is defined and is displayed on the console.
An empty list is defined.
The original list is iterated over, and conditions are set to check if the values at specific indices are less than or greater than 0.
Depending on this, the index is appended to the empty list.
This is displayed as the output on the console.
- Python program to get the indices of each element of one list in another list
- Program to get indices of a list after deleting elements in ascending order in Python
- Get indices of True values in a binary list in Python
- Python program to remove elements at Indices in List
- Find elements of a list by indices in Python
- Program to find local peak element indices from a list of numbers in Python
- Get match indices in Python
- Python - Ways to find indices of value in list
- Program to find length of longest sign alternating subsequence from a list of numbers in Python
- Python program to display Astrological sign or Zodiac sign for a given data of birth.
- Change the sign of a value to that of another in Numpy
- Python Group elements at same indices in a multi-list
- Python – Character indices Mapping in String List
- Python Program to get all unique keys from a List of Dictionaries
- Python program to get maximum of each key Dictionary List