当前位置: 首页>>代码示例>>Python>>正文


Python moves.zip_longest方法代码示例

本文整理汇总了Python中six.moves.zip_longest方法的典型用法代码示例。如果您正苦于以下问题:Python moves.zip_longest方法的具体用法?Python moves.zip_longest怎么用?Python moves.zip_longest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在six.moves的用法示例。


在下文中一共展示了moves.zip_longest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __eq__

# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import zip_longest [as 别名]
def __eq__(self, other):
        if callable_attr(other, 'iterallitems'):
            myiter, otheriter = self.iterallitems(), other.iterallitems()
            for i1, i2 in zip_longest(myiter, otheriter, fillvalue=_absent):
                if i1 != i2 or i1 is _absent or i2 is _absent:
                    return False
        elif not hasattr(other, '__len__') or not hasattr(other, _items_attr):
            return False
        # Ignore order so we can compare ordered omdicts with unordered dicts.
        else:
            if len(self) != len(other):
                return False
            for key, value in six.iteritems(other):
                if self.get(key, _absent) != value:
                    return False
        return True 
开发者ID:pypa,项目名称:pipenv,代码行数:18,代码来源:orderedmultidict.py

示例2: calc_consistency_score

# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import zip_longest [as 别名]
def calc_consistency_score(segment_one, segment_two, offset_one, offset_two):
    """Calculate the number of bases aligned to the same reference bases in two
    alignments.
    :param segment_one: Pysam aligned segments.
    :param segment_two: Pysam aligned segments.
    :param offset_one: Hard clipping offset for the first alignment.
    :param offset_two: Hard clipping offset for the second alignment.
    :retruns: Number of matching base alignments.
    :rtype: int
     """
    matches_one = aligned_pairs_to_matches(
        segment_one.get_aligned_pairs(), offset_one)
    matches_two = aligned_pairs_to_matches(
        segment_two.get_aligned_pairs(), offset_two)

    score = 0
    for matches in zip_longest(matches_one, matches_two, fillvalue=False):
        if matches[0] == matches[1]:
            score += 1

    return score 
开发者ID:nanoporetech,项目名称:wub,代码行数:23,代码来源:compare.py

示例3: test_parse_into_tasks

# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import zip_longest [as 别名]
def test_parse_into_tasks(
        self, structure_and_messages1, structure_and_messages2, structure_and_messages3
    ):
        """
        Adding messages to a L{Parser} parses them into a L{Task} instances.
        """
        _, messages1 = structure_and_messages1
        _, messages2 = structure_and_messages2
        _, messages3 = structure_and_messages3
        all_messages = (messages1, messages2, messages3)
        # Need unique UUIDs per task:
        assume(len(set(m[0][TASK_UUID_FIELD] for m in all_messages)) == 3)

        parser = Parser()
        all_tasks = []
        for message in chain(*zip_longest(*all_messages)):
            if message is not None:
                completed_tasks, parser = parser.add(message)
                all_tasks.extend(completed_tasks)

        assertCountEqual(
            self, all_tasks, [parse_to_task(msgs) for msgs in all_messages]
        ) 
开发者ID:itamarst,项目名称:eliot,代码行数:25,代码来源:test_parse.py

示例4: test_multiplicative_adjustments

# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import zip_longest [as 别名]
def test_multiplicative_adjustments(self,
                                        name,
                                        data,
                                        lookback,
                                        adjustments,
                                        missing_value,
                                        perspective_offset,
                                        expected):

        array = AdjustedArray(data, NOMASK, adjustments, missing_value)
        for _ in range(2):  # Iterate 2x ensure adjusted_arrays are re-usable.
            window_iter = array.traverse(
                lookback,
                perspective_offset=perspective_offset,
            )
            for yielded, expected_yield in zip_longest(window_iter, expected):
                check_arrays(yielded, expected_yield) 
开发者ID:enigmampc,项目名称:catalyst,代码行数:19,代码来源:test_adjusted_array.py

示例5: test_overwrite_adjustment_cases

# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import zip_longest [as 别名]
def test_overwrite_adjustment_cases(self,
                                        name,
                                        baseline,
                                        lookback,
                                        adjustments,
                                        missing_value,
                                        perspective_offset,
                                        expected):
        array = AdjustedArray(baseline, NOMASK, adjustments, missing_value)

        for _ in range(2):  # Iterate 2x ensure adjusted_arrays are re-usable.
            window_iter = array.traverse(
                lookback,
                perspective_offset=perspective_offset,
            )
            for yielded, expected_yield in zip_longest(window_iter, expected):
                check_arrays(yielded, expected_yield) 
开发者ID:enigmampc,项目名称:catalyst,代码行数:19,代码来源:test_adjusted_array.py

示例6: get

# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import zip_longest [as 别名]
def get(self, content=True, links=True, comments=True):

        _content = self.gen_content_reqs(self.ids) if content else []
        _links = self.gen_links_reqs(self.ids) if links else []
        _comments = self.get_comments(self.ids, self.metas) if comments else ()

        def gen_posts():
            for content, links, comments in zip_longest(
                api.imap(_content), api.imap(_links), _comments
            ):
                post = {}
                post.update(content.json()) if content else None
                post.update({
                    'links': links.json() if links else None,
                    'comments': self.extract_comments(comments)
                })
                if post:
                    yield post

            logger.info('[Posts.gen_posts <gen>] Processed.')

        return PostsResult(gen_posts) 
开发者ID:leVirve,项目名称:dcard-spider,代码行数:24,代码来源:posts.py

示例7: test_move_items

# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import zip_longest [as 别名]
def test_move_items(item_name):
    """Ensure that everything loads correctly."""
    try:
        item = getattr(six.moves, item_name)
        if isinstance(item, types.ModuleType):
            __import__("six.moves." + item_name)
    except AttributeError:
        if item_name == "zip_longest" and sys.version_info < (2, 6):
            py.test.skip("zip_longest only available on 2.6+")
    except ImportError:
        if item_name == "winreg" and not sys.platform.startswith("win"):
            py.test.skip("Windows only module")
        if item_name.startswith("tkinter"):
            if not have_tkinter:
                py.test.skip("requires tkinter")
            if item_name == "tkinter_ttk" and sys.version_info[:2] <= (2, 6):
                py.test.skip("ttk only available on 2.7+")
        if item_name.startswith("dbm_gnu") and not have_gdbm:
            py.test.skip("requires gdbm")
        raise
    if sys.version_info[:2] >= (2, 6):
        assert item_name in dir(six.moves) 
开发者ID:NiklasRosenstein,项目名称:c4ddev,代码行数:24,代码来源:test_six.py

示例8: obj_check

# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import zip_longest [as 别名]
def obj_check(a, b):
    c = None
    if not isinstance(a, type(b)):
        c = a
    else:
        if isinstance(a, dict):
            c = obj_merge(a, b)
        elif isinstance(a, list):
            z = []
            for x, y in zip_longest(a, b, fillvalue=empty):
                if x is empty:
                    z.append(y)
                elif y is empty:
                    z.append(x)
                else:
                    z.append(obj_check(x, y))
            c = z
        else:
            c = a
    return c 
开发者ID:kelproject,项目名称:pykube,代码行数:22,代码来源:utils.py

示例9: _CheckVmCallCounts

# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import zip_longest [as 别名]
def _CheckVmCallCounts(self, spec, working_groups, working_expected_counts,
                         non_working_groups, non_working_expected_counts):
    # TODO(skschneider): This is also used in TestBackgroundNetworkWorkload.
    # Consider moving to a shared function or base class.
    expected_call_counts = {group: working_expected_counts
                            for group in working_groups}
    expected_call_counts.update({group: non_working_expected_counts
                                 for group in non_working_groups})
    for group_name, vm_expected_call_counts in six.iteritems(
        expected_call_counts):
      group_vms = spec.vm_groups[group_name]
      self.assertEqual(len(group_vms), 1,
                       msg='VM group "{0}" had {1} VMs'.format(group_name,
                                                               len(group_vms)))
      vm = group_vms[0]
      iter_mocked_functions = zip_longest(_MOCKED_VM_FUNCTIONS,
                                          vm_expected_call_counts)
      for function_name, expected_call_count in iter_mocked_functions:
        call_count = getattr(vm, function_name).call_count
        self.assertEqual(call_count, expected_call_count, msg=(
            'Expected {0} from VM group "{1}" to be called {2} times, but it '
            'was called {3} times.'.format(function_name, group_name,
                                           expected_call_count, call_count))) 
开发者ID:GoogleCloudPlatform,项目名称:PerfKitBenchmarker,代码行数:25,代码来源:background_network_workload_test.py

示例10: averageSeries

# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import zip_longest [as 别名]
def averageSeries(requestContext, *seriesLists):
    """
    Short Alias: avg()

    Takes one metric or a wildcard seriesList.
    Draws the average value of all metrics passed at each time.

    Example::

        &target=averageSeries(company.server.*.threads.busy)

    """
    if not seriesLists or not any(seriesLists):
        return []
    seriesList, start, end, step = normalize(seriesLists)
    name = "averageSeries(%s)" % formatPathExpressions(seriesList)
    values = (safeDiv(safeSum(row), safeLen(row))
              for row in zip_longest(*seriesList))
    series = TimeSeries(name, start, end, step, values)
    series.pathExpression = name
    return [series] 
开发者ID:brutasse,项目名称:graphite-api,代码行数:23,代码来源:functions.py

示例11: create_cells

# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import zip_longest [as 别名]
def create_cells(headers, schema_fields, values=None, row_number=None):
    """Create list of cells from headers, fields and values.

    Args:
        headers (List[str]): The headers values.
        schema_fields (List[tableschema.field.Field]): The tableschema
            fields.
        values (List[Any], optional): The cells values. If not specified,
            the created cells will have the same values as their
            corresponding headers. This is useful for specifying headers
            cells.
            If the list has any `None` values, as is the case on empty
            cells, the resulting Cell will have an empty string value. If
            the `values` list has a different length than the `headers`,
            the resulting Cell will have value `None`.
        row_number (int, optional): The row number.

    Returns:
        List[dict]: List of cells.
    """
    fillvalue = '_fillvalue'
    is_header_row = (values is None)
    cells = []

    iterator = zip_longest(headers, schema_fields, values or [], fillvalue=fillvalue)
    for column_number, (header, field, value) in enumerate(iterator, start=1):
        is_virtual = header == fillvalue and value == fillvalue or None
        if header == fillvalue:
            header = None
        elif is_header_row:
            value = header
        if field == fillvalue:
            field = None
        if value == fillvalue:
            value = None
        cell = create_cell(header, value, field, column_number, row_number, is_virtual)
        cells.append(cell)

    return cells 
开发者ID:frictionlessdata,项目名称:goodtables-py,代码行数:41,代码来源:cells.py

示例12: grouper

# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import zip_longest [as 别名]
def grouper(n, iterable, padvalue=None):
    "grouper(3, 'abcdefg', 'x') --> ('a','b','c'), ('d','e','f'), ('g','x','x')"
    return zip_longest(*[iter(iterable)]*n, fillvalue=padvalue) 
开发者ID:cambridgeltl,项目名称:link-prediction_with_deep-learning,代码行数:5,代码来源:graph.py

示例13: grouper

# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import zip_longest [as 别名]
def grouper(iterable, n=2, fillvalue=None):
    "Collect data into fixed-length chunks or blocks"
    # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx"
    args = [iter(iterable)] * n
    return zip_longest(*args, fillvalue=fillvalue) 
开发者ID:tensorprob,项目名称:tensorprob,代码行数:7,代码来源:utilities.py

示例14: grouper

# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import zip_longest [as 别名]
def grouper(iterable, n, fillvalue=None, shorten=False, num_groups=None):
    args = [iter(iterable)] * n
    out = zip_longest(*args, fillvalue=fillvalue)
    out = list(out)
    if num_groups is not None:
        default = (fillvalue,) * n
        assert isinstance(num_groups, int)
        out = list(each for each, _ in zip_longest(out, range(num_groups), fillvalue=default))
    if shorten:
        assert fillvalue is None
        out = (tuple(e for e in each if e is not None) for each in out)
    return out 
开发者ID:misonuma,项目名称:strsum,代码行数:14,代码来源:data_structure.py

示例15: __eq__

# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import zip_longest [as 别名]
def __eq__(self, other):
        for (n1, key1, value1), (n2, key2, value2) in zip_longest(self, other):
            if key1 != key2 or value1 != value2:
                return False
        return True 
开发者ID:pypa,项目名称:pipenv,代码行数:7,代码来源:itemlist.py


注:本文中的six.moves.zip_longest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。