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


Python future_builtins.filter方法代码示例

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


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

示例1: first

# 需要导入模块: import future_builtins [as 别名]
# 或者: from future_builtins import filter [as 别名]
def first(iterable, default=None, key=None):
    """Return first element of *iterable* that evaluates to ``True``, else
    return ``None`` or optional *default*. Similar to :func:`one`.
    >>> first([0, False, None, [], (), 42])
    42
    >>> first([0, False, None, [], ()]) is None
    True
    >>> first([0, False, None, [], ()], default='ohai')
    'ohai'
    >>> import re
    >>> m = first(re.match(regex, 'abc') for regex in ['b.*', 'a(.*)'])
    >>> m.group(1)
    'bc'

    The optional *key* argument specifies a one-argument predicate function
    like that used for *filter()*.  The *key* argument, if supplied, should be
    in keyword form. For example, finding the first even number in an iterable:
    >>> first([1, 1, 3, 4, 5], key=lambda x: x % 2 == 0)
    4

    Contributed by Hynek Schlawack, author of `the original standalone module`_.
    .. _the original standalone module: https://github.com/hynek/first
    """
    return next(filter(key, iterable), default) 
开发者ID:HunterMcGushion,项目名称:hyperparameter_hunter,代码行数:26,代码来源:boltons_utils.py

示例2: test_overall

# 需要导入模块: import future_builtins [as 别名]
# 或者: from future_builtins import filter [as 别名]
def test_overall(self):
        speed = league.PlayerSpeedDistanceTracking(date_from='03/05/2016',
                                                   date_to='03/05/2016', season="2015-16")
        assert speed
        overall = speed.overall()
        assert overall
        iter = filter(lambda d: d['PLAYER_NAME'] == 'Derrick Rose', overall)
        stats = next(iter)
        assert stats
        assert stats['GP'] == 1
        assert stats['MIN'] == 29.25
        assert stats['DIST_MILES'] == 2.24
        assert stats['DIST_FEET'] == 11827.0
        assert stats['DIST_MILES_OFF'] == 1.29
        assert stats['DIST_MILES_DEF'] == 0.95
        assert stats['AVG_SPEED'] == 4.52
        assert stats['AVG_SPEED_OFF'] == 4.94
        assert stats['AVG_SPEED_DEF'] == 4.42 
开发者ID:seemethere,项目名称:nba_py,代码行数:20,代码来源:test_nba_py_league.py

示例3: test_overall

# 需要导入模块: import future_builtins [as 别名]
# 或者: from future_builtins import filter [as 别名]
def test_overall(self):
        results = draftcombine.Summary(season=self.season)
        assert results

        overall = results.overall()
        assert overall

        stats = next(filter(lambda d: d['PLAYER_NAME'] == self.player_name, overall))
        assert stats

        assert stats['POSITION'] == 'SG'
        assert stats['MAX_VERTICAL_LEAP'] == 34.5
        assert stats['MODIFIED_LANE_AGILITY_TIME'] == 2.75
        assert stats['STANDING_REACH'] == 102.5
        assert stats['HEIGHT_WO_SHOES'] == 76.5
        assert stats['WINGSPAN'] == 80.25
        assert stats['STANDING_VERTICAL_LEAP'] == 27.5
        assert stats['BENCH_PRESS'] == 8
        assert stats['HAND_WIDTH'] == 9.0
        assert stats['HEIGHT_W_SHOES'] == 77.75
        assert stats['THREE_QUARTER_SPRINT'] == 3.28
        assert stats['HAND_LENGTH'] == 8.75
        assert stats['LANE_AGILITY_TIME'] == 10.27
        assert stats['BODY_FAT_PCT'] == 8.3 
开发者ID:seemethere,项目名称:nba_py,代码行数:26,代码来源:test_nba_py_draftcombine.py

示例4: test_itertools

# 需要导入模块: import future_builtins [as 别名]
# 或者: from future_builtins import filter [as 别名]
def test_itertools(self):
        from itertools import imap, izip, ifilter
        # We will assume that the itertools functions work, so provided
        # that we've got identical coppies, we will work!
        self.assertEqual(map, imap)
        self.assertEqual(zip, izip)
        self.assertEqual(filter, ifilter)
        # Testing that filter(None, stuff) raises a warning lives in
        # test_py3kwarn.py 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_future_builtins.py

示例5: find_pred

# 需要导入模块: import future_builtins [as 别名]
# 或者: from future_builtins import filter [as 别名]
def find_pred(self, pred):
        "Find all nodes where pred(tree) == True"
        return filter(pred, self.iter_subtrees()) 
开发者ID:lark-parser,项目名称:lark,代码行数:5,代码来源:tree.py

示例6: map_filter

# 需要导入模块: import future_builtins [as 别名]
# 或者: from future_builtins import filter [as 别名]
def map_filter(self, function, test):
        """Filter with test then apply function."""
        if function is None:
            function = lambda x: x  # return results of filter
        return list(map(function, filter(test, self.entities))) 
开发者ID:apache,项目名称:qpid-dispatch,代码行数:7,代码来源:agent.py

示例7: map_type

# 需要导入模块: import future_builtins [as 别名]
# 或者: from future_builtins import filter [as 别名]
def map_type(self, function, type):
        """Apply function to all entities of type, if type is None do all
        entities"""
        if function is None:
            function = lambda x: x
        if type is None:
            return list(map(function, self.entities))
        else:
            if not isinstance(type, EntityType):
                type = self.schema.entity_type(type)
            return list(map(function, filter(lambda e: e.entity_type.is_a(type),
                                             self.entities))) 
开发者ID:apache,项目名称:qpid-dispatch,代码行数:14,代码来源:agent.py

示例8: one

# 需要导入模块: import future_builtins [as 别名]
# 或者: from future_builtins import filter [as 别名]
def one(src, default=None, key=None):
    """Along the same lines as builtins, :func:`all` and :func:`any`, and
    similar to :func:`first`, ``one()`` returns the single object in
    the given iterable *src* that evaluates to ``True``, as determined
    by callable *key*. If unset, *key* defaults to :class:`bool`. If
    no such objects are found, *default* is returned. If *default* is
    not passed, ``None`` is returned.
    If *src* has more than one object that evaluates to ``True``, or
    if there is no object that fulfills such condition, return
    *default*. It's like an `XOR`_ over an iterable.
    >>> one((True, False, False))
    True
    >>> one((True, False, True))
    >>> one((0, 0, 'a'))
    'a'
    >>> one((0, False, None))
    >>> one((True, True), default=False)
    False
    >>> bool(one(('', 1)))
    True
    >>> one((10, 20, 30, 42), key=lambda i: i > 40)
    42

    See `Martín Gaitán's original repo`_ for further use cases.
    .. _Martín Gaitán's original repo: https://github.com/mgaitan/one
    .. _XOR: https://en.wikipedia.org/wiki/Exclusive_or
    """
    ones = list(itertools.islice(filter(key, src), 2))
    return ones[0] if len(ones) == 1 else default 
开发者ID:HunterMcGushion,项目名称:hyperparameter_hunter,代码行数:31,代码来源:boltons_utils.py


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