“Python”的版本间的差异

来自wrc's Wiki
跳到导航 跳到搜索
第1行: 第1行:
 +
== 笔记 ==
 +
 +
=== 复杂度 ===
 +
 +
* len(a_list) 复杂度为 O(1)
 +
 
== 例子 ==
 
== 例子 ==
  

2021年5月24日 (一) 08:33的版本

笔记

复杂度

  • len(a_list) 复杂度为 O(1)

例子

实现 Rust 中的 Iterator::skip

忽略一个迭代器的前 n 个元素。

[1]

itertools.islice(iterable, stop)
itertools.islice(iterable, start, stop[, step])
from itertools import islice

islice(iterator, n, None)

类的静态方法

class Example:
    @classmethod
    def load(cls, filepath):
        obj = cls.__new__(cls)
        obj.foo = somefunc(filepath)
        return obj

外部链接

参考资料