-2

This return only the first index value where the char is present in the list. I need all the indices where char is present.

  def find_loc(char):
    for sub_list in chunks:
        if char in sub_list:
                return chunks.index(sub_list), sub_list.index(char)
shivam singhal
  • 156
  • 4
  • 9
  • Flagging for "Very low quality". Have a look at ["How do I ask a good question?"](https://stackoverflow.com/help/how-to-ask) – Paco H. Sep 20 '17 at 11:36
  • 1
    Possible duplicate of [How to find all occurrences of an element in a list?](https://stackoverflow.com/questions/6294179/how-to-find-all-occurrences-of-an-element-in-a-list) – Chris_Rands Sep 20 '17 at 11:41

2 Answers2

0

Index method returns the first index value encountered.

Help on method_descriptor:

index(...)
    L.index(value, [start, [stop]]) -> integer -- return first index of value.
    Raises ValueError if the value is not present.
bhansa
  • 7,282
  • 3
  • 30
  • 55
0

Use this snippet:

def indexes(iterable, obj):
    encounters = []
    for i in range(len(iterable)):
        if iterable[i] == obj:
            encounters.append(i)
    return encounters
Kotauskas
  • 1,239
  • 11
  • 31