Is it possible to find all the positions of
HSE in the nested loop below?
map1 = [ [' ', ' ', ' ', ' '],\ [' ', ' ', 'SHP', ' '],\ [' ', 'HSE', 'HSE', 'FAC'],\ [' ', 'BCH', ' ', 'HSE'] ]
I am only aware of using index, but it returns the first value only. Below is my codes:
HSE_list =  for x in map1: if 'HSE' in x: y = (map1.index(x), x.index('HSE')) HSE_list.append(y) print(HSE_list)
It returns the first item in every list which comes in contact with, so no matter how many
HSE I have in the nested loop, it will still only show the first
HSE that it sees in
map. My print will return as:
[(2, 1), (3, 3)] when I run the program.
is there any way that I can make it show all the positions of the house in my nested list,
[(2, 1), (2, 2), (3, 3)]?