代理列表到列表返回函数
lazylist的Python项目详细描述
这个小程序包提供一个代理列表到列表返回函数:
>>> from lazylist import LazyList >>> l = LazyList(lambda: x) >>> x = [1, 2, 3] >>> list(l) [1, 2, 3]
更准确地说,view函数不必返回精确的list, 但是任何静噪对象,例如str,tuple:
>>> x = "hello" >>> list(l) ['h', 'e', 'l', 'l', 'o']
它满足collections.abc.Sequence协议:
>>> from collections import Sequence >>> isinstance(l, Sequence) True >>> l[-1] 'o' >>> len(l) 5
但是,它不满足collections.abc.MutableSequence协议。 换句话说,它是不可变的:
>>> from collections import MutableSequence >>> isinstance(l, MutableSequence) False >>> l[0] = 'H' Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'LazyList' object does not support item assignment
分布在lgplv3或更高版本下。
待办事项
- LazySet
- LazyMap