Exemple #1
0
def eat(iterator, amount):
    """Advance an iterator n-steps ahead. If n is None, eat entirely.

  Taken from the Python documentation. Under the PSF license.

  :param iterator:
      An iterator.
  :param amount:
      The number of steps to advance.
  :yields:
      An iterator.
  """
    # Use functions that consume iterators at C speed.
    if amount is None:
        # Feed the entire iterator into a zero-length deque.
        collections.deque(iterator)
    else:
        # Advance to the empty slice starting at position n.
        builtins.next(itertools.islice(iterator, amount, amount), None)
Exemple #2
0
def eat(iterator, amount):
  """Advance an iterator n-steps ahead. If n is None, eat entirely.

  Taken from the Python documentation. Under the PSF license.

  :param iterator:
      An iterator.
  :param amount:
      The number of steps to advance.
  :yields:
      An iterator.
  """
  # Use functions that consume iterators at C speed.
  if amount is None:
    # Feed the entire iterator into a zero-length deque.
    collections.deque(iterator)
  else:
    # Advance to the empty slice starting at position n.
    builtins.next(itertools.islice(iterator, amount, amount), None)
Exemple #3
0
def nth(iterable, index, default=None):
    """Returns the nth element out of an iterable.

  :param iterable:
      Iterable sequence.
  :param index:
      Index
  :param default:
      If not found, this or ``None`` will be returned.
  :returns:
      nth element of the iterable sequence.
  """
    return builtins.next(itertools.islice(iterable, index, None), default)
Exemple #4
0
def nth(iterable, index, default=None):
  """Returns the nth element out of an iterable.

  :param iterable:
      Iterable sequence.
  :param index:
      Index
  :param default:
      If not found, this or ``None`` will be returned.
  :returns:
      nth element of the iterable sequence.
  """
  return builtins.next(itertools.islice(iterable, index, None), default)
Exemple #5
0
 def walker(path, topdown=topdown, followlinks=followlinks):
   """Alternative walker."""
   yield builtins.next(os.walk(path,
                               topdown=topdown,
                               followlinks=followlinks))
Exemple #6
0
 def walker(path, topdown=topdown, followlinks=followlinks):
     """Alternative walker."""
     yield builtins.next(
         os.walk(path, topdown=topdown, followlinks=followlinks))