當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。