{"id":14604,"date":"2021-09-30T16:30:16","date_gmt":"2021-09-30T11:00:16","guid":{"rendered":"https:\/\/python-programs.com\/?p=14604"},"modified":"2021-11-22T18:34:24","modified_gmt":"2021-11-22T13:04:24","slug":"python-program-to-find-indices-of-the-non-zero-elements-in-the-python-list","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-find-indices-of-the-non-zero-elements-in-the-python-list\/","title":{"rendered":"Python Program to Find Indices of the Non-Zero Elements in the Python list"},"content":{"rendered":"

We’ll look at how to determine the indices of non-zero entries in a Python list. There may be times when we simply need to access the list’s non-zero elements. In such instances, we can apply the following techniques.<\/p>\n

Lists:<\/strong><\/p>\n

A list is an ordered grouping of values. It can hold a variety of values. A list is a container that may be changed. This means that we can add new values, delete old ones, or change current ones.<\/p>\n

A Python list is a mathematical concept that describes a finite sequence. Items or elements in a list are the values in a list. A list can have multiple instances of the same value. Each occurrence is treated as a separate item.<\/p>\n

Given a list, the task is to find the indices of non-zero elements in the given list.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given list = [11, 19, 0, 8, 45, 0, 29, 0, 19, 0, 26, 0, 33]<\/pre>\n

Output:<\/strong><\/p>\n

The non zero elements indices in the given list are =  [0, 1, 3, 4, 6, 8, 10, 12]<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given list = 25 0 7 0 0 0 9 5<\/pre>\n

Output:<\/strong><\/p>\n

The non zero elements indices in the given list are = [0, 2, 6, 7]<\/pre>\n

Program to Find Indices of the Non-Zero Elements in the Python list in Python<\/h2>\n

Below are the ways to find the indices of non-zero elements in the given list.<\/p>\n