title: How to get the last line as Index in a text file with python like len[arry]-1) on a arry?
body: <p>I have a very large file of hashes and a hash I gave. I want to compare this given hash with the file to see if it is in the file.
  I chose BinarySearch for this. My current problem is to find the correct index for the rightmost element.</p>
  
  <pre><code>def binarySearch (l, r, x):
  
  # Check base case
  if r &gt;= l:
  
  mid = l + (r - l)/2
  
  # If element is present at the middle itself
  if getLineFromFile(mid) == x:
      return mid
  
  # If element is smaller than mid, then it
  # can only be present in left subarray
  elif getLineFromFile(mid) &gt; x:
      return binarySearch(l, mid-1, x)
  
  # Else the element can only be present
  # in right subarray
  else:
      return binarySearch(mid + 1, r, x)
  
  else:
     # Element is not present in the array
     return -1
  
  x = '0000000A0E3B9F25FF41DE4B5AC238C2D545C7A8:15'
  
  def getLineFromFile(lineNumber):
   with open('testfile.txt') as f:
    for i, line in enumerate(f):
     if i == lineNumber:
      return line
  else:
   print('Not 7 lines in file')
   line = None
  
  # get last Element of List
  def tail():
   for line in open('pwned.txt', 'r'):
     pass
  else:
    print line
  
  ausgabetail = tail()
  #print ausgabetail
  result = binarySearch( 0, ausgabetail, x)
  if result != -1:
    print "Element is present at index % d" % result
  else:
     print "Element is not present in array"
  </code></pre>
  
  <p>My problem now is to get the correct index for the right side for the binary search. I pass the function (l, r, x). The left side starts at the beginning with 0. The right side should be the end of the file so the last line. I try to get that but it doesn't work. I tried to get this with the Funktion tail(). But if I print r on testing, I get the value "None". Do you have another idea here?</p>