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


Python itertools.dropwhile方法代码示例

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


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

示例1: lines

# 需要导入模块: import itertools [as 别名]
# 或者: from itertools import dropwhile [as 别名]
def lines(self):
        """Return the source code lines for this error."""
        source = ''
        lines = self.definition.source
        offset = self.definition.start
        lines_stripped = list(reversed(list(dropwhile(is_blank,
                                                      reversed(lines)))))
        numbers_width = len(str(offset + len(lines_stripped)))
        line_format = '{{:{}}}:{{}}'.format(numbers_width)
        for n, line in enumerate(lines_stripped):
            if line:
                line = ' ' + line
            source += line_format.format(n + offset, line)
            if n > 5:
                source += '        ...\n'
                break
        return source 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:19,代码来源:violations.py

示例2: __init__

# 需要导入模块: import itertools [as 别名]
# 或者: from itertools import dropwhile [as 别名]
def __init__(self, provider, objects, limit=None, marker=None):
        self._objects = objects
        limit = limit or provider.config.default_result_limit
        total_size = len(objects)
        if marker:
            from_marker = itertools.dropwhile(
                lambda obj: not obj.id == marker, objects)
            # skip one past the marker
            next(from_marker, None)
            objects = list(from_marker)
        is_truncated = len(objects) > limit
        results = list(itertools.islice(objects, limit))
        super(ClientPagedResultList, self).__init__(
            is_truncated,
            results[-1].id if is_truncated else None,
            True, total=total_size,
            data=results) 
开发者ID:CloudVE,项目名称:cloudbridge,代码行数:19,代码来源:resources.py

示例3: skip_while

# 需要导入模块: import itertools [as 别名]
# 或者: from itertools import dropwhile [as 别名]
def skip_while(collection, predicate):
    """:yaql:skipWhile

    Skips elements from the collection as long as the predicate is true.
    Then returns an iterator to collection of remaining elements

    :signature: collection.skipWhile(predicate)
    :receiverArg collection: input collection
    :argType collection: iterable
    :arg predicate: function of one argument to apply to every collection value
    :argType predicate: lambda
    :returnType: iterator

    .. code::

        yaql> [1, 2, 3, 4, 5].skipWhile($ < 3)
        [3, 4, 5]
    """
    return itertools.dropwhile(predicate, collection) 
开发者ID:openstack,项目名称:yaql,代码行数:21,代码来源:queries.py

示例4: source

# 需要导入模块: import itertools [as 别名]
# 或者: from itertools import dropwhile [as 别名]
def source(self):
        """Return the source code for the definition."""
        full_src = self._source[self._slice]

        def is_empty_or_comment(line):
            return line.strip() == '' or line.strip().startswith('#')

        filtered_src = dropwhile(is_empty_or_comment, reversed(full_src))
        return ''.join(reversed(list(filtered_src))) 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:11,代码来源:parser.py

示例5: _ver_2_list

# 需要导入模块: import itertools [as 别名]
# 或者: from itertools import dropwhile [as 别名]
def _ver_2_list(version):
        version = [int(i) for i in version.split(".")]
        return list(
            reversed(list(itertools.dropwhile(lambda i: i == 0, reversed(version))))
        ) 
开发者ID:pypa,项目名称:linehaul,代码行数:7,代码来源:test_strategies.py

示例6: write_pot_file

# 需要导入模块: import itertools [as 别名]
# 或者: from itertools import dropwhile [as 别名]
def write_pot_file(potfile, msgs):
    """
    Write the :param potfile: POT file with the :param msgs: contents,
    previously making sure its format is valid.
    """
    if os.path.exists(potfile):
        # Strip the header
        msgs = '\n'.join(dropwhile(len, msgs.split('\n')))
    else:
        msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8')
    with io.open(potfile, 'a', encoding='utf-8') as fp:
        fp.write(msgs) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:14,代码来源:makemessages.py

示例7: go_data

# 需要导入模块: import itertools [as 别名]
# 或者: from itertools import dropwhile [as 别名]
def go_data(ofile):
    """Skip header.

    the first next() call of the returned iterator will be the @data line"""
    return itertools.dropwhile(lambda x: not r_datameta.match(x), ofile)


#----------------
# Parsing header
#---------------- 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:12,代码来源:arffread.py

示例8: split_on

# 需要导入模块: import itertools [as 别名]
# 或者: from itertools import dropwhile [as 别名]
def split_on(iterable, element):
    preceding = list(takewhile(lambda _: _ != element, iterable))
    following = list(dropwhile(lambda _: _ != element, iterable))
    return preceding, (following[1:] if len(following) > 0 else None) 
开发者ID:mesosphere-backup,项目名称:deimos,代码行数:6,代码来源:docker.py

示例9: order_by

# 需要导入模块: import itertools [as 别名]
# 或者: from itertools import dropwhile [as 别名]
def order_by(self, *field_names):
        '''
        Returns a list of the QuerySetSequence items with the ordering changed.
        '''
        # construct a comparator function based on the field names prefixes
        reverses = [1] * len(field_names)
        field_names = list(field_names)
        for i in range(len(field_names)):
            field_name = field_names[i]
            if field_name[0] == '-':
                reverses[i] = -1
                field_names[i] = field_name[1:]

        # wanna iterable and attrgetter returns single item if 1 arg supplied
        def fields_getter(i):
            return chain_sing(attrgetter(*field_names)(i))

        # comparator gets the first non-zero value of the field comparison
        # results taking into account reverse order for fields prefixed with '-'
        def comparator(i1, i2):
            return dropwhile(
                __not__,
                mul_it(map(cmp, fields_getter(i1), fields_getter(i2)), reverses)
            ).next()

        # return new sorted list
        return sorted(self.collapse(), cmp=comparator) 
开发者ID:certsocietegenerale,项目名称:FIR,代码行数:29,代码来源:querysets.py

示例10: get_streams_to_sync

# 需要导入模块: import itertools [as 别名]
# 或者: from itertools import dropwhile [as 别名]
def get_streams_to_sync(streams, state):
    target_stream = singer.get_currently_syncing(state)
    result = streams
    if target_stream:
        skipped = list(itertools.takewhile(
            lambda x: x.tap_stream_id != target_stream, streams))
        rest = list(itertools.dropwhile(
            lambda x: x.tap_stream_id != target_stream, streams))
        result = rest + skipped # Move skipped streams to end
    if not result:
        raise Exception('Unknown stream {} in state'.format(target_stream))
    return result 
开发者ID:singer-io,项目名称:tap-hubspot,代码行数:14,代码来源:__init__.py

示例11: new_parameters

# 需要导入模块: import itertools [as 别名]
# 或者: from itertools import dropwhile [as 别名]
def new_parameters(self, input_shape, input_dtype, rng):
    del input_dtype
    if len(input_shape) > 4:
      self._check_nhwc()
      new_batch_dim = six.moves.reduce(operator.mul, input_shape[:-3])
      input_shape = [new_batch_dim] + list(input_shape[-3:])
    kernel_shape = self._kernel_shape(input_shape)
    bias_shape = [self._filters if c == 'C' else 1 for c in self._out_spec]
    bias_shape = tuple(itertools.dropwhile(lambda x: x == 1, bias_shape))
    w = self._kernel_initializer(kernel_shape, rng)
    b = self._bias_initializer(bias_shape, rng)
    return (w, b) 
开发者ID:yyht,项目名称:BERT,代码行数:14,代码来源:convolution.py

示例12: meet

# 需要导入模块: import itertools [as 别名]
# 或者: from itertools import dropwhile [as 别名]
def meet(cls, a: 'VariableStack', b: 'VariableStack') -> 'VariableStack':
        """
        Return the meet of the given stacks, taking the element-wise meets of their
        contained Variables from the top down.
        """

        pairs = zip_longest(reversed(a.value), reversed(b.value),
                            fillvalue=Variable.bottom())
        max_size = a.max_size if a.max_size < b.max_size else b.max_size
        return cls(dropwhile(lambda x: x.is_bottom,
                             [Variable.meet(*p) for p in pairs][::-1]),
                   max_size) 
开发者ID:nevillegrech,项目名称:MadMax,代码行数:14,代码来源:memtypes.py

示例13: get_after

# 需要导入模块: import itertools [as 别名]
# 或者: from itertools import dropwhile [as 别名]
def get_after(sentinel, iterable):
    """Get the value after `sentinel` in an `iterable`"""
    truncated = dropwhile(lambda el: el != sentinel, iterable)
    next(truncated)
    return next(truncated) 
开发者ID:apache,项目名称:airflow,代码行数:7,代码来源:test_spark_sql.py

示例14: init_weights_and_state

# 需要导入模块: import itertools [as 别名]
# 或者: from itertools import dropwhile [as 别名]
def init_weights_and_state(self, input_signature):
    input_shape = input_signature.shape
    if len(input_shape) > 4:
      self._check_nhwc()
      new_batch_dim = functools.reduce(operator.mul, input_shape[:-3])
      input_shape = [new_batch_dim] + list(input_shape[-3:])
    kernel_shape = self._kernel_shape(input_shape)
    bias_shape = [self._filters if c == 'C' else 1 for c in self._out_spec]
    bias_shape = tuple(itertools.dropwhile(lambda x: x == 1, bias_shape))
    rng1, rng2 = fastmath.random.split(self.rng, 2)
    w = self._kernel_initializer(kernel_shape, rng1)
    b = self._bias_initializer(bias_shape, rng2)
    self.weights = (w, b) 
开发者ID:google,项目名称:trax,代码行数:15,代码来源:convolution.py

示例15: test_dropwhile

# 需要导入模块: import itertools [as 别名]
# 或者: from itertools import dropwhile [as 别名]
def test_dropwhile():
    base = (verify_same, dropwhile, itertools.dropwhile, None)
    yield base + (bool,)
    yield base + (bool, [])
    yield base + (bool, [5, 5, 2, 0, 0])
    yield base + (bool, [1, 2, 0, 4, 0])
    yield base + (partial(lt, 3), range(5, 0, -1))
    base = (verify_pickle, dropwhile, itertools.dropwhile)
    yield base + (2, 1, bool, [5, 5, 2, 0, 0])
    yield base + (2, 0, bool, [5, 5, 2, 0, 0])
    yield base + (3, 0, bool, [1, 2, 0, 4, 0])
    yield base + (3, 2, bool, [1, 2, 0, 4, 0]) 
开发者ID:mila-iqia,项目名称:picklable-itertools,代码行数:14,代码来源:__init__.py


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