title: Find list index of list items within other list items
body: <p>I have a list of long strings and I'd like to get the indexes of the list elements that match a substring of strings in another list. Checking if a list item contains a a single string inside a list is easy to do with list comprehensions, like <a href="https://stackoverflow.com/questions/4843158/check-if-a-python-list-item-contains-a-string-inside-another-string?rq=1">this question</a>:</p>
  
  <pre><code>my_list = ['abc-123', 'def-456', 'ghi-789', 'abc-456']
  thing_to_find = "abc"
  matching = [i for i, x in enumerate(my_list) if thing_to_find in x]
  </code></pre>
  
  <p>However, I'd like to check not only if <code>"abc"</code> is in <code>x</code>, but if any strings in another list are in the list, like so:</p>
  
  <pre><code>my_list = ['abc-123', 'def-456', 'ghi-789', 'abc-456']
  things_to_find = ['abc', 'def']
  </code></pre>
  
  <p>This obviously doesn't work (but it would be really cool if it did):</p>
  
  <pre><code>matching = [i for i, x in enumerate(my_list) if things_to_find in x]
  </code></pre>
  
  <p>I can find the list indexes if I run commands individually, but it's tedious and horrible:</p>
  
  <pre><code>print([i for i, x in enumerate(my_list) if 'abc' in x])
  # [0, 3]
  print([i for i, x in enumerate(my_list) if 'def' in x])
  # [1]
  </code></pre>
  
  <p>What's the best way to find the indexes of all instances where elements from one list are found in another list?</p>