def _get_bucket_filter_leading(bucket, len_seq):
  """Filtering function for sequence "contains" a "leading bucket".

  All n-grams in the leading bucket must be of the same length. The length of
  the sequence to be subject to the filtering function must be of length
  len_seq, and it must be longer than the n-grams in the leading bucket.

  A sequence is here defined as "containing" a "leading bucket" if the leading
  n-gram of the sequence, of the same length as the n-grams in the bucket, is
  present in the bucket.

  E.g.
  bucket = ["as", "we", "op"]
  seqs = ["asdf", "qwer", "uiop"]
  seqs filters to: ["asdf"]

  Args:
    bucket: Bucket of n-grams used to filter sequences.
    len_seq: Length of sequences to be filtered.

  Returns: Filter function for sequence to be filtered "containing" bucket.
  """
  len_ng = len(bucket[0])
  assert len_ng < len_seq
  bucket_set = set(bucket)

  def filter_fn(seq):
    assert len(seq) == len_seq
    return seq[:len_ng] in bucket_set

  return filter_fn