
"""Small utility functions for use in various places."""

__all__ = ["pick", "is_dunder", "convert_to_od", "counter_to_iterable"]

import collections
import itertools

def pick(arg, default):
    """Handler for default versus given argument."""
    return default if arg is None else arg

def is_dunder(name):
    """Return True if a __dunder__ name, False otherwise."""
    return name[:2] == name[-2:] == "__" and "_" not in (name[2:3], name[-3:-2])

def convert_to_od(mapping, order):
    """Convert mapping to an OrderedDict instance using order."""
    return collections.OrderedDict([(i, mapping[i]) for i in order])

def counter_to_iterable(counter):
    """Convert a counter to an iterable / iterator."""
    for item in itertools.starmap(itertools.repeat, counter):
        yield from item


"""Small utility functions for use in various places."""

__all__ = ["pick", "is_dunder", "convert_to_od",
           "counter_to_iterable", "count"]

import collections
import itertools

def pick(arg, default):
    """Handler for default versus given argument."""
    return default if arg is None else arg

def is_dunder(name):
    """Return True if a __dunder__ name, False otherwise."""
    return name[:2] == name[-2:] == "__" and "_" not in (name[2:3], name[-3:-2])

def convert_to_od(mapping, order):
    """Convert mapping to an OrderedDict instance using order."""
    return collections.OrderedDict([(i, mapping[i]) for i in order])

def counter_to_iterable(counter):
    """Convert a counter to an iterable / iterator."""
    for item in itertools.starmap(itertools.repeat, counter):
        yield from item

def count(iterable):
    """Yield (item, count) two-tuples of the iterable."""
    seen = []
    full = list(iterable)

    for item in full:
        if item in seen:
            continue
        seen.append(item)
        yield (item, full.count(item))

Add a new 'count' utility function
Add a new 'count' utility function

  
  """Small utility functions for use in various places."""
  
- __all__ = ["pick", "is_dunder", "convert_to_od", "counter_to_iterable"]
+ __all__ = ["pick", "is_dunder", "convert_to_od",
+            "counter_to_iterable", "count"]
  
  import collections
  import itertools
  
  def pick(arg, default):
      """Handler for default versus given argument."""
      return default if arg is None else arg
  
  def is_dunder(name):
      """Return True if a __dunder__ name, False otherwise."""
      return name[:2] == name[-2:] == "__" and "_" not in (name[2:3], name[-3:-2])
  
  def convert_to_od(mapping, order):
      """Convert mapping to an OrderedDict instance using order."""
      return collections.OrderedDict([(i, mapping[i]) for i in order])
  
  def counter_to_iterable(counter):
      """Convert a counter to an iterable / iterator."""
      for item in itertools.starmap(itertools.repeat, counter):
          yield from item
  
+ def count(iterable):
+     """Yield (item, count) two-tuples of the iterable."""
+     seen = []
+     full = list(iterable)
+ 
+     for item in full:
+         if item in seen:
+             continue
+         seen.append(item)
+         yield (item, full.count(item))
+ 
Add a new 'count' utility function
## Code Before:

"""Small utility functions for use in various places."""

__all__ = ["pick", "is_dunder", "convert_to_od", "counter_to_iterable"]

import collections
import itertools

def pick(arg, default):
    """Handler for default versus given argument."""
    return default if arg is None else arg

def is_dunder(name):
    """Return True if a __dunder__ name, False otherwise."""
    return name[:2] == name[-2:] == "__" and "_" not in (name[2:3], name[-3:-2])

def convert_to_od(mapping, order):
    """Convert mapping to an OrderedDict instance using order."""
    return collections.OrderedDict([(i, mapping[i]) for i in order])

def counter_to_iterable(counter):
    """Convert a counter to an iterable / iterator."""
    for item in itertools.starmap(itertools.repeat, counter):
        yield from item

## Instruction:
Add a new 'count' utility function
## Code After:

"""Small utility functions for use in various places."""

__all__ = ["pick", "is_dunder", "convert_to_od",
           "counter_to_iterable", "count"]

import collections
import itertools

def pick(arg, default):
    """Handler for default versus given argument."""
    return default if arg is None else arg

def is_dunder(name):
    """Return True if a __dunder__ name, False otherwise."""
    return name[:2] == name[-2:] == "__" and "_" not in (name[2:3], name[-3:-2])

def convert_to_od(mapping, order):
    """Convert mapping to an OrderedDict instance using order."""
    return collections.OrderedDict([(i, mapping[i]) for i in order])

def counter_to_iterable(counter):
    """Convert a counter to an iterable / iterator."""
    for item in itertools.starmap(itertools.repeat, counter):
        yield from item

def count(iterable):
    """Yield (item, count) two-tuples of the iterable."""
    seen = []
    full = list(iterable)

    for item in full:
        if item in seen:
            continue
        seen.append(item)
        yield (item, full.count(item))
