How can I improve this?

When I ran this in the terminal, the output was the index of every match since I passed x inside of lst1.index(x). Can you help me understand why it wouldn’t work? I’ll check my terminal when I get home to make sure it wasn’t returning a solution from another piece of code.

Test with lists that contain duplicates to see what I mean.

1 Like

Nooooow I see what you’re saying. I’ll keep tinkering.

1 Like

Then I guess the only dirty way I can think of with my limited knowledge of all of the different methods or functions is:

def same_values(lst1, lst2):
  index = 0
  empty = []
  for x, y in zip(lst1, lst2):
    if x == y:
      empty.append(index)
      index += 1
    else:
      index += 1
  return empty
def same_values(lst1, lst2):
  index = -1
  empty = []
  for x, y in zip(lst1, lst2):
    index += 1
    if x == y:
      empty.append(index)
  return empty

It follows from your code on a refactoring vein.

1 Like

Ahhh - this makes sense.

1 Like