本文整理汇总了Python中more_itertools.first_true方法的典型用法代码示例。如果您正苦于以下问题:Python more_itertools.first_true方法的具体用法?Python more_itertools.first_true怎么用?Python more_itertools.first_true使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类more_itertools
的用法示例。
在下文中一共展示了more_itertools.first_true方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_hyperparam_byname
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import first_true [as 别名]
def get_hyperparam_byname(name: str, gbdt_type: str = 'lgbm', with_metadata: bool = False) -> Dict:
"""
Get a hyperparameter by parameter name
Args:
name:
The name of parameter (e.g. "ieee-2019-10th").
gbdt_type:
The type of gbdt library. ``lgbm``, ``cat``, ``xgb`` can be used.
with_metadata:
When set to True, parameters are wrapped by metadata dictionary which contains information about
source URL, competition name etc.
Returns:
A hyperparameter dictionary.
"""
param_table = _get_table(gbdt_type)
found = first_true(param_table, pred=lambda x: x['name'] == name)
if found is None:
raise RuntimeError('Hyperparameter {} not found.'.format(name))
return _return(found, with_metadata)
示例2: test_something_true
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import first_true [as 别名]
def test_something_true(self):
"""Test with no keywords"""
self.assertEqual(mi.first_true(range(10)), 1)
示例3: test_nothing_true
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import first_true [as 别名]
def test_nothing_true(self):
"""Test default return value."""
self.assertIsNone(mi.first_true([0, 0, 0]))
示例4: test_default
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import first_true [as 别名]
def test_default(self):
"""Test with a default keyword"""
self.assertEqual(mi.first_true([0, 0, 0], default='!'), '!')
示例5: test_pred
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import first_true [as 别名]
def test_pred(self):
"""Test with a custom predicate"""
self.assertEqual(
mi.first_true([2, 4, 6], pred=lambda x: x % 3 == 0), 6
)
示例6: _get_hyperparam_byname
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import first_true [as 别名]
def _get_hyperparam_byname(param_table: List[Dict], name: str, with_metadata: bool):
found = first_true(param_table, pred=lambda x: x['name'] == name)
if found is None:
raise RuntimeError('Hyperparameter {} not found.'.format(name))
if with_metadata:
return found
else:
return found['parameters']