<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import , print_function , division <EOL> import sys <EOL> if sys . version_info [ : <NUM_LIT:2> ] < ( <NUM_LIT:2> , <NUM_LIT:7> ) : <EOL> from UserDict import DictMixin <EOL> class OrderedDict ( dict , DictMixin ) : <EOL> def __init__ ( self , * args , ** kwds ) : <EOL> if len ( args ) > <NUM_LIT:1> : <EOL> raise TypeError ( '<STR_LIT>' % <EOL> len ( args ) ) <EOL> try : <EOL> self . __end <EOL> except AttributeError : <EOL> self . clear ( ) <EOL> self . update ( * args , ** kwds ) <EOL> def clear ( self ) : <EOL> self . __end = end = [ ] <EOL> end += [ None , end , end ] <EOL> self . __map = { } <EOL> dict . clear ( self ) <EOL> def __setitem__ ( self , key , value ) : <EOL> if key not in self : <EOL> end = self . __end <EOL> curr = end [ <NUM_LIT:1> ] <EOL> curr [ <NUM_LIT:2> ] = end [ <NUM_LIT:1> ] = self . __map [ key ] = [ key , curr , end ] <EOL> dict . __setitem__ ( self , key , value ) <EOL> def __delitem__ ( self , key ) : <EOL> dict . __delitem__ ( self , key ) <EOL> key , prev , next = self . __map . pop ( key ) <EOL> prev [ <NUM_LIT:2> ] = next <EOL> next [ <NUM_LIT:1> ] = prev <EOL> def __iter__ ( self ) : <EOL> end = self . __end <EOL> curr = end [ <NUM_LIT:2> ] <EOL> while curr is not end : <EOL> yield curr [ <NUM_LIT:0> ] <EOL> curr = curr [ <NUM_LIT:2> ] <EOL> def __reversed__ ( self ) : <EOL> end = self . __end <EOL> curr = end [ <NUM_LIT:1> ] <EOL> while curr is not end : <EOL> yield curr [ <NUM_LIT:0> ] <EOL> curr = curr [ <NUM_LIT:1> ] <EOL> def popitem ( self , last = True ) : <EOL> if not self : <EOL> raise KeyError ( '<STR_LIT>' ) <EOL> if last : <EOL> key = next ( reversed ( self ) ) <EOL> else : <EOL> key = next ( iter ( self ) ) <EOL> value = self . pop ( key ) <EOL> return key , value <EOL> def __reduce__ ( self ) : <EOL> items = [ [ k , self [ k ] ] for k in self ] <EOL> tmp = self . __map , self . __end <EOL> del self . __map , self . __end <EOL> inst_dict = vars ( self ) . copy ( ) <EOL> self . __map , self . __end = tmp <EOL> if inst_dict : <EOL> return ( self . __class__ , ( items , ) , inst_dict ) <EOL> return self . __class__ , ( items , ) <EOL> def keys ( self ) : <EOL> return list ( self ) <EOL> setdefault = DictMixin . setdefault <EOL> update = DictMixin . update <EOL> pop = DictMixin . pop <EOL> values = DictMixin . values <EOL> items = DictMixin . items <EOL> iterkeys = DictMixin . iterkeys <EOL> itervalues = DictMixin . itervalues <EOL> iteritems = DictMixin . iteritems <EOL> def __repr__ ( self ) : <EOL> if not self : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , ) <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , list ( self . items ( ) ) ) <EOL> def copy ( self ) : <EOL> return self . __class__ ( self ) <EOL> @ classmethod <EOL> def fromkeys ( cls , iterable , value = None ) : <EOL> d = cls ( ) <EOL> for key in iterable : <EOL> d [ key ] = value <EOL> return d <EOL> def __eq__ ( self , other ) : <EOL> if isinstance ( other , OrderedDict ) : <EOL> if len ( self ) != len ( other ) : <EOL> return False <EOL> for p , q in zip ( self . items ( ) , other . items ( ) ) : <EOL> if p != q : <EOL> return False <EOL> return True <EOL> return dict . __eq__ ( self , other ) <EOL> def __ne__ ( self , other ) : <EOL> return not self == other <EOL> from operator import itemgetter <EOL> from heapq import nlargest <EOL> from itertools import repeat <EOL> from theano . compat import ifilter <EOL> class Counter ( dict ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , iterable = None , ** kwds ) : <EOL> '''<STR_LIT>''' <EOL> self . update ( iterable , ** kwds ) <EOL> def __missing__ ( self , key ) : <EOL> return <NUM_LIT:0> <EOL> def most_common ( self , n = None ) : <EOL> '''<STR_LIT>''' <EOL> if n is None : <EOL> return sorted ( self . iteritems ( ) , key = itemgetter ( <NUM_LIT:1> ) , <EOL> reverse = True ) <EOL> return nlargest ( n , self . iteritems ( ) , key = itemgetter ( <NUM_LIT:1> ) ) <EOL> def elements ( self ) : <EOL> '''<STR_LIT>''' <EOL> for elem , count in self . iteritems ( ) : <EOL> for _ in repeat ( None , count ) : <EOL> yield elem <EOL> @ classmethod <EOL> def fromkeys ( cls , iterable , v = None ) : <EOL> raise NotImplementedError ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def update ( self , iterable = None , ** kwds ) : <EOL> '''<STR_LIT>''' <EOL> if iterable is not None : <EOL> if hasattr ( iterable , '<STR_LIT>' ) : <EOL> if self : <EOL> self_get = self . get <EOL> for elem , count in iterable . iteritems ( ) : <EOL> self [ elem ] = self_get ( elem , <NUM_LIT:0> ) + count <EOL> else : <EOL> dict . update ( self , iterable ) <EOL> else : <EOL> self_get = self . get <EOL> for elem in iterable : <EOL> self [ elem ] = self_get ( elem , <NUM_LIT:0> ) + <NUM_LIT:1> <EOL> if kwds : <EOL> self . update ( kwds ) <EOL> def copy ( self ) : <EOL> '''<STR_LIT>''' <EOL> return Counter ( self ) <EOL> def __delitem__ ( self , elem ) : <EOL> '''<STR_LIT>''' <EOL> if elem in self : <EOL> dict . __delitem__ ( self , elem ) <EOL> def __repr__ ( self ) : <EOL> if not self : <EOL> return '<STR_LIT>' % self . __class__ . __name__ <EOL> items = '<STR_LIT:U+002CU+0020>' . join ( map ( '<STR_LIT>' . __mod__ , self . most_common ( ) ) ) <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , items ) <EOL> def __add__ ( self , other ) : <EOL> '''<STR_LIT>''' <EOL> if not isinstance ( other , Counter ) : <EOL> return NotImplemented <EOL> result = Counter ( ) <EOL> for elem in set ( self ) | set ( other ) : <EOL> newcount = self [ elem ] + other [ elem ] <EOL> if newcount > <NUM_LIT:0> : <EOL> result [ elem ] = newcount <EOL> return result <EOL> def __sub__ ( self , other ) : <EOL> '''<STR_LIT>''' <EOL> if not isinstance ( other , Counter ) : <EOL> return NotImplemented <EOL> result = Counter ( ) <EOL> for elem in set ( self ) | set ( other ) : <EOL> newcount = self [ elem ] - other [ elem ] <EOL> if newcount > <NUM_LIT:0> : <EOL> result [ elem ] = newcount <EOL> return result <EOL> def __or__ ( self , other ) : <EOL> '''<STR_LIT>''' <EOL> if not isinstance ( other , Counter ) : <EOL> return NotImplemented <EOL> _max = max <EOL> result = Counter ( ) <EOL> for elem in set ( self ) | set ( other ) : <EOL> newcount = _max ( self [ elem ] , other [ elem ] ) <EOL> if newcount > <NUM_LIT:0> : <EOL> result [ elem ] = newcount <EOL> return result <EOL> def __and__ ( self , other ) : <EOL> '''<STR_LIT>''' <EOL> if not isinstance ( other , Counter ) : <EOL> return NotImplemented <EOL> _min = min <EOL> result = Counter ( ) <EOL> if len ( self ) < len ( other ) : <EOL> self , other = other , self <EOL> for elem in ifilter ( self . __contains__ , other ) : <EOL> newcount = _min ( self [ elem ] , other [ elem ] ) <EOL> if newcount > <NUM_LIT:0> : <EOL> result [ elem ] = newcount <EOL> return result <EOL> else : <EOL> try : <EOL> from UserDict import DictMixin <EOL> except ImportError : <EOL> from collections import MutableMapping as DictMixin <EOL> from collections import OrderedDict , Counter <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] </s>
