title: Iterate through a List Multiple times Cyclically starting from the Matching Index
body: <p>I need to do the following in python.  I have a list of strings, <code>list</code>, a string to search for, <code>text</code>, and variable containing the number of elements to print, <code>x</code>.  I want to iterate through <code>x</code> no. of consecutive elements of the <code>list</code>, wrapping around to the front of <code>list</code> if necessary.  </p>
  
  <p>First I need to find the first element in <code>list</code> that has <code>text</code> as a substring.  I will then start with the first element of <code>list</code> <em>after</em> that matched element, and continue to iterate through a total of <code>x</code> consecutive elements of the <code>list</code>, wrapping around if necessary.</p>
  
  <p>How would I do this?</p>
  
  <pre><code>x = 11
  text = "string5"
  list = ["string1", "string2", "string3", "string4", "string5", "string6", "string7"]
  
  # not sure what to do here...
  for elem in list:
      if text in elem:
          #iterate through list, begin with elem and get the next 11 elements
          #once you've reached string7, start over with string1`
  </code></pre>
  
  <p>In this example I want to end up looking at the following 11 elements:</p>
  
  <pre><code>string6
  string7
  string1
  string2
  string3
  string4
  string5
  string6
  string7
  string1
  string2
  </code></pre>