本文整理汇总了Python中collections.defaultdict.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python defaultdict.__init__方法的具体用法?Python defaultdict.__init__怎么用?Python defaultdict.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类collections.defaultdict
的用法示例。
在下文中一共展示了defaultdict.__init__方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from collections import defaultdict [as 别名]
# 或者: from collections.defaultdict import __init__ [as 别名]
def __init__(self, function, *lists, **config):
"""
:param function: The function that should be applied to
elements of ``lists``. It should take as many arguments
as there are ``lists``.
:param lists: The underlying lists.
:param cache_size: Determines the size of the cache used
by this lazy map. (default=5)
"""
if not lists:
raise TypeError('LazyMap requires at least two args')
self._lists = lists
self._func = function
self._cache_size = config.get('cache_size', 5)
self._cache = ({} if self._cache_size > 0 else None)
# If you just take bool() of sum() here _all_lazy will be true just
# in case n >= 1 list is an AbstractLazySequence. Presumably this
# isn't what's intended.
self._all_lazy = sum(isinstance(lst, AbstractLazySequence)
for lst in lists) == len(lists)
示例2: __init__
# 需要导入模块: from collections import defaultdict [as 别名]
# 或者: from collections.defaultdict import __init__ [as 别名]
def __init__(self, samples=None):
"""
Construct a new frequency distribution. If ``samples`` is
given, then the frequency distribution will be initialized
with the count of each object in ``samples``; otherwise, it
will be initialized to be empty.
In particular, ``FreqDist()`` returns an empty frequency
distribution; and ``FreqDist(samples)`` first creates an empty
frequency distribution, and then calls ``update`` with the
list ``samples``.
:param samples: The samples to initialize the frequency
distribution with.
:type samples: Sequence
"""
Counter.__init__(self, samples)
示例3: __init__
# 需要导入模块: from collections import defaultdict [as 别名]
# 或者: from collections.defaultdict import __init__ [as 别名]
def __init__(self, parent, trace, node_label, firsthit, leaf, depth, seqID):
"""
initialize a node in the graph
here a node keeps record of trace i.e. from where the node is reached (the edge label)
so nodes with same other attributes may have different trace
"""
self.parent = parent
self.trace = trace
self.node_label = node_label
self.firsthit = firsthit
self.leaf = leaf
self.depth = depth
self.children = []
self.seqID = seqID
#Node.node_id += 1
#self.node_id = node_id
示例4: __init__
# 需要导入模块: from collections import defaultdict [as 别名]
# 或者: from collections.defaultdict import __init__ [as 别名]
def __init__(
self, name, definition, container_definition=None, tags=None,
):
from .solid import ISolidDefinition, CompositeSolidDefinition
self.name = check.str_param(name, 'name')
self.definition = check.inst_param(definition, 'definition', ISolidDefinition)
self.container_definition = check.opt_inst_param(
container_definition, 'container_definition', CompositeSolidDefinition
)
self._additional_tags = validate_tags(tags)
input_handles = {}
for name, input_def in self.definition.input_dict.items():
input_handles[name] = SolidInputHandle(self, input_def)
self._input_handles = input_handles
output_handles = {}
for name, output_def in self.definition.output_dict.items():
output_handles[name] = SolidOutputHandle(self, output_def)
self._output_handles = output_handles
示例5: __init__
# 需要导入模块: from collections import defaultdict [as 别名]
# 或者: from collections.defaultdict import __init__ [as 别名]
def __init__(self, function, *lists, **config):
"""
:param function: The function that should be applied to
elements of ``lists``. It should take as many arguments
as there are ``lists``.
:param lists: The underlying lists.
:param cache_size: Determines the size of the cache used
by this lazy map. (default=5)
"""
if not lists:
raise TypeError('LazyMap requires at least two args')
self._lists = lists
self._func = function
self._cache_size = config.get('cache_size', 5)
if self._cache_size > 0:
self._cache = {}
else:
self._cache = None
# If you just take bool() of sum() here _all_lazy will be true just
# in case n >= 1 list is an AbstractLazySequence. Presumably this
# isn't what's intended.
self._all_lazy = sum(isinstance(lst, AbstractLazySequence)
for lst in lists) == len(lists)
示例6: __init__
# 需要导入模块: from collections import defaultdict [as 别名]
# 或者: from collections.defaultdict import __init__ [as 别名]
def __init__(self, samples=None):
"""
Construct a new frequency distribution. If ``samples`` is
given, then the frequency distribution will be initialized
with the count of each object in ``samples``; otherwise, it
will be initialized to be empty.
In particular, ``FreqDist()`` returns an empty frequency
distribution; and ``FreqDist(samples)`` first creates an empty
frequency distribution, and then calls ``update`` with the
list ``samples``.
:param samples: The samples to initialize the frequency
distribution with.
:type samples: Sequence
"""
dict.__init__(self)
self._N = 0
self._reset_caches()
if samples:
self.update(samples)