本文整理匯總了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))