title: Python fastest search in a list of tuple/list that returns the index
body: <p>I have a list/tuples of tuples/list (doesnt matter which one I use) where the value of the inner list or tuple has variable sizes. I need to check if a variable is in the first slot inner list or tuple.</p>
  <blockquote>
  <p>Structure looks like this:</p>
  <p>[ [[list of x amount of ints],[same number of ints as first slot],[[y number of ints], [z number of ints], .... , [a number of ints]], ... repeated about 20x]</p>
  </blockquote>
  <p>Example:</p>
  <blockquote>
  <p>([1, 21, 54, 55, 93, 99, 284, 393, 964, 1029, 1214, 1216, 1223, 1253, 1258, 1334, 1365, 1394, 1397, 1453, 1471, 1543, 1589, 1824, 1975, 2054, 2090, 2164, 2165, 2166, 2167, 2323, 2547, 2645, 2802, 2809, 2931, 2958, 3031, 3071, 3077, 3078, 3189, 3199, 3202, 3203], [1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 2, 1, 1, 1, 2, 4, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 4, 2, 1, 1, 1, 1, 1, 2, 3, 1, 2, 1, 3, 3, 1, 2], [[3], [1], [4], [2], [12], [6], [3], [8], [20, 27], [11], [4, 7], [71], [133], [14, 74], [6], [67], [34], [3, 16], [9, 7, 23, 71], [11, 43], [67], [71], [4], [139], [16], [52], [4], [31], [7, 50], [2, 12], [1, 1, 83, 114], [13, 70], [60], [121], [30], [16], [214], [29, 78], [9, 37, 60], [14], [216, 249], [28], [2, 2, 21], [4, 18, 22], [59], [8, 24]])</p>
  <p>This is just the first value of my list of 20k+ elements that is similar.</p>
  </blockquote>
  <p>So I have a function to check if a number is in:</p>
  <blockquote>
  <p>[1, 21, 54, 55, 93, 99, 284, 393, 964, 1029, 1214, 1216, 1223, 1253, 1258, 1334, 1365, 1394, 1397, 1453, 1471, 1543, 1589, 1824, 1975, 2054, 2090, 2164, 2165, 2166, 2167, 2323, 2547, 2645, 2802, 2809, 2931, 2958, 3031, 3071, 3077, 3078, 3189, 3199, 3202, 3203]</p>
  </blockquote>
  <p>And it will return the index.</p>
  <p>My function:
  iD is the number I'm searching for, and posting is just the first element in my nest loop (the direct block above is an example of posting)</p>
  <pre><code>def searchCurrentPosting(iD,posting):
  x = 0
  
  for each in posting[0]:
      if iD == each:
           return x
      x += 1
  return False
  </code></pre>
  <p>I have to run this search function every time a new word is given(20k to the power of some given number). This code will run for about a minute. Anyway to shave down the time?</p>
  <p>Edit: If you want my whole program here it is:</p>
  <p>This is my main driver: <a href="http://pastebin.com/Udjit7PP" rel="nofollow noreferrer">http://pastebin.com/Udjit7PP</a></p>
  <p>File it parse is:  CACM collection which is the standard for IR testing.</p>
  <p>Stemming used (port stemming): <a href="http://pastebin.com/AzA0fvdV" rel="nofollow noreferrer">http://pastebin.com/AzA0fvdV</a></p>
  <p>And Yes, I am creating an inverted index.</p>