code: def linearsearch(iter_, key, prev_size=0, compare_func=cmp):
      
  
      prev_deque = deque(maxlen=prev_size + 1)
  
      matched = False
  
      for line in iter_:
          prev_deque.append(line)
          if compare_func(line, key) >= 0:
              matched = True
              break
  
      # no matches, so return empty iterator
      if not matched:
          return iter([])
  
      return itertools.chain(prev_deque, iter_)
docs: Perform a linear search over iterator until
      current_line >= key
  
      optionally also tracking upto N previous lines, which are
      returned before the first matched line.
  
      if end of stream is reached before a match is found,
      nothing is returned (prev lines discarded also)