當前位置: 首頁>>代碼示例>>Python>>正文


Python more_itertools.windowed方法代碼示例

本文整理匯總了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) 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:6,代碼來源:test_more.py

示例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) 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:10,代碼來源:test_more.py

示例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) 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:14,代碼來源:test_more.py

示例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) 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:7,代碼來源:test_more.py

示例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)) 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:6,代碼來源:test_more.py


注:本文中的more_itertools.windowed方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。