# Python | K Value Indices Product

Usually, we require to find the index, in which the particular value is located. There are many method to achieve that, using index() etc. But sometimes require to find all the indices of a particular value in case it has multiple occurrences in list and compute their product. Lets discuss certain ways to do so.

Method #1 : Naive Method
We can achieve this task by iterating through the list and check for that value and just append the value index in new list and print that. This is the basic brute force method to achieve this task. The task of performing product is done by loop.

 `# Python code to demonstrate  ` `# K Value Indices Product ` `# using naive method  ` ` `  `# initializing list  ` `test_list ``=` `[``1``, ``3``, ``4``, ``3``, ``6``, ``7``, ``3``] ` ` `  `# printing initial list  ` `print` `(``"Original list : "` `+` `str``(test_list)) ` ` `  `# initializing K  ` `K ``=` `3` ` `  `# using naive method ` `# K Value Indices Product ` `res ``=` `1` `for` `i ``in` `range``(``0``, ``len``(test_list)) : ` `    ``if` `test_list[i] ``=``=` `K : ` `        ``res ``*``=` `i ` ` `  `# printing resultant list  ` `print` `(``"K Value indices product is : "` `+` `str``(res)) `

Output :

```Original list : [1, 3, 4, 3, 6, 7, 3]
K Value indices product is : 18
```

Method #2 : Using `enumerate()` + loop
Using enumerate() we can achieve the similar task, this is slightly faster technique than above and hence is recommended to be used over the list comprehension technique. The task of performing product is done by loop.

 `# Python code to demonstrate  ` `# K Value Indices Product ` `# using enumerate() ` ` `  `# getting Product  ` `def` `prod(val) :  ` `    ``res ``=` `1`  `    ``for` `ele ``in` `val:  ` `        ``res ``*``=` `ele  ` `    ``return` `res   ` ` `  `# initializing list  ` `test_list ``=` `[``1``, ``3``, ``4``, ``3``, ``6``, ``7``, ``3``] ` ` `  `# printing initial list  ` `print` `(``"Original list : "` `+` `str``(test_list)) ` ` `  `# initializing K  ` `K ``=` `3` ` `  `# using enumerate() ` `# K Value Indices Product ` `res ``=` `prod([i ``for` `i, value ``in` `enumerate``(test_list) ``if` `value ``=``=` `K]) ` ` `  `# printing resultant list  ` `print` `(``"K Value indices product is : "` `+` `str``(res)) `

Output :

```Original list : [1, 3, 4, 3, 6, 7, 3]
K Value indices product is : 18
```

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.