本文整理汇总了Python中more_itertools.windowed方法的典型用法代码示例。如果您正苦于以下问题:Python more_itertools.windowed方法的具体用法?Python more_itertools.windowed怎么用?Python more_itertools.windowed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类more_itertools
的用法示例。
在下文中一共展示了more_itertools.windowed方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_basic
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import windowed [as 别名]
def test_basic(self):
actual = list(mi.windowed([1, 2, 3, 4, 5], 3))
expected = [(1, 2, 3), (2, 3, 4), (3, 4, 5)]
self.assertEqual(actual, expected)
示例2: test_large_size
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import windowed [as 别名]
def test_large_size(self):
"""
When the window size is larger than the iterable, and no fill value is
given,``None`` should be filled in.
"""
actual = list(mi.windowed([1, 2, 3, 4, 5], 6))
expected = [(1, 2, 3, 4, 5, None)]
self.assertEqual(actual, expected)
示例3: test_fillvalue
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import windowed [as 别名]
def test_fillvalue(self):
"""
When sizes don't match evenly, the given fill value should be used.
"""
iterable = [1, 2, 3, 4, 5]
for n, kwargs, expected in [
(6, {}, [(1, 2, 3, 4, 5, '!')]), # n > len(iterable)
(3, {'step': 3}, [(1, 2, 3), (4, 5, '!')]), # using ``step``
]:
actual = list(mi.windowed(iterable, n, fillvalue='!', **kwargs))
self.assertEqual(actual, expected)
示例4: test_zero
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import windowed [as 别名]
def test_zero(self):
"""When the window size is zero, an empty tuple should be emitted."""
actual = list(mi.windowed([1, 2, 3, 4, 5], 0))
expected = [tuple()]
self.assertEqual(actual, expected)
示例5: test_negative
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import windowed [as 别名]
def test_negative(self):
"""When the window size is negative, ValueError should be raised."""
with self.assertRaises(ValueError):
list(mi.windowed([1, 2, 3, 4, 5], -1))