Python future_builtins.filter() Examples
The following are 15
code examples of future_builtins.filter().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
future_builtins
, or try the search function
.
Example #1
Source File: tree.py From lark with MIT License | 6 votes |
def find_pred(self, pred): "Find all nodes where pred(tree) == True" return filter(pred, self.iter_subtrees())
Example #2
Source File: boltons_utils.py From hyperparameter_hunter with MIT License | 6 votes |
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)
Example #3
Source File: test_nba_py_league.py From nba_py with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #4
Source File: test_nba_py_draftcombine.py From nba_py with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #5
Source File: test_future_builtins.py From ironpython2 with Apache License 2.0 | 5 votes |
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
Example #6
Source File: test_future_builtins.py From BinderFilter with MIT License | 5 votes |
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
Example #7
Source File: test_future_builtins.py From oss-ftp with MIT License | 5 votes |
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
Example #8
Source File: agent.py From qpid-dispatch with Apache License 2.0 | 5 votes |
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)))
Example #9
Source File: agent.py From qpid-dispatch with Apache License 2.0 | 5 votes |
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)))
Example #10
Source File: test_future_builtins.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #11
Source File: boltons_utils.py From hyperparameter_hunter with MIT License | 5 votes |
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
Example #12
Source File: test_future_builtins.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
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
Example #13
Source File: test_nba_py_draftcombine.py From nba_py with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_overall(self): results = draftcombine.DrillResults(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_VERTICAL_LEAP'] == 27.5 assert stats['THREE_QUARTER_SPRINT'] == 3.28
Example #14
Source File: test_future_builtins.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
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
Example #15
Source File: test_nba_py_draftcombine.py From nba_py with BSD 3-Clause "New" or "Revised" License | 4 votes |
def test_overall(self): results = draftcombine.SpotShooting(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['PLAYER_NAME'] == self.player_name assert stats['COLLEGE_BREAK_LEFT_MADE'] == None assert stats['COLLEGE_BREAK_LEFT_PCT'] == None assert stats['COLLEGE_BREAK_RIGHT_ATTEMPT'] == None assert stats['COLLEGE_BREAK_RIGHT_MADE'] == None assert stats['COLLEGE_BREAK_RIGHT_PCT'] == None assert stats['COLLEGE_CORNER_LEFT_ATTEMPT'] == None assert stats['COLLEGE_CORNER_LEFT_MADE'] == None assert stats['COLLEGE_CORNER_LEFT_PCT'] == None assert stats['COLLEGE_CORNER_RIGHT_ATTEMPT'] == None assert stats['COLLEGE_CORNER_RIGHT_MADE'] == None assert stats['COLLEGE_CORNER_RIGHT_PCT'] == None assert stats['COLLEGE_TOP_KEY_ATTEMPT'] == None assert stats['COLLEGE_TOP_KEY_MADE'] == None assert stats['COLLEGE_TOP_KEY_PCT'] == None assert stats['FIFTEEN_BREAK_LEFT_ATTEMPT'] == None assert stats['FIFTEEN_BREAK_LEFT_MADE'] == None assert stats['FIFTEEN_BREAK_LEFT_PCT'] == None assert stats['FIFTEEN_BREAK_RIGHT_ATTEMPT'] == None assert stats['FIFTEEN_BREAK_RIGHT_MADE'] == None assert stats['FIFTEEN_BREAK_RIGHT_PCT'] == None assert stats['FIFTEEN_CORNER_LEFT_ATTEMPT'] == None assert stats['FIFTEEN_CORNER_LEFT_MADE'] == None assert stats['FIFTEEN_CORNER_LEFT_PCT'] == None assert stats['FIFTEEN_CORNER_RIGHT_ATTEMPT'] == None assert stats['FIFTEEN_CORNER_RIGHT_MADE'] == None assert stats['FIFTEEN_CORNER_RIGHT_PCT'] == None assert stats['FIFTEEN_TOP_KEY_ATTEMPT'] == None assert stats['FIFTEEN_TOP_KEY_MADE'] == None assert stats['FIFTEEN_TOP_KEY_PCT'] == None assert stats['NBA_BREAK_LEFT_ATTEMPT'] == None assert stats['NBA_BREAK_LEFT_MADE'] == None assert stats['NBA_BREAK_LEFT_PCT'] == None assert stats['NBA_BREAK_RIGHT_ATTEMPT'] == None assert stats['NBA_BREAK_RIGHT_MADE'] == None assert stats['NBA_BREAK_RIGHT_PCT'] == None assert stats['NBA_CORNER_LEFT_ATTEMPT'] == None assert stats['NBA_CORNER_LEFT_MADE'] == None assert stats['NBA_CORNER_LEFT_PCT'] == None assert stats['NBA_CORNER_RIGHT_ATTEMPT'] == None assert stats['NBA_CORNER_RIGHT_MADE'] == None assert stats['NBA_CORNER_RIGHT_PCT'] == None assert stats['NBA_TOP_KEY_ATTEMPT'] == None assert stats['NBA_TOP_KEY_MADE'] == None assert stats['NBA_TOP_KEY_PCT'] == None assert stats['PLAYER_ID'] == None