小编Non*_*ons的帖子

How to diff the two files using Python Generator

I have one file of 100GB having 1 to 1000000000000 separated by new line. In this some lines are missing like 5, 11, 19919 etc. My Ram size is 8GB.

How to find the missing elements.

My idea take another file for i in range(1,1000000000000) read the lines one by one using the generator. can we use yield statement for this

Can help in writing the code

My Code, the below code taking as a list in does the …

python generator range

6
推荐指数
2
解决办法
271
查看次数

Python generator time complexity log(n)

In python3 range built with help of generators

对数时间— O(log n)当算法在每一步中减少输入数据的大小时,被称为具有对数时间复杂度。例如,如果我们要在生成器的帮助下打印前10位数字,则首先将得到一个元素,因此剩下的9个元素必须处理,然后再得到第二个元素,因此剩下的8个元素必须处理

for index in range(0, len(data)):
    print(data[index])
Run Code Online (Sandbox Code Playgroud)

当我检查python生成器的时间复杂度时,它说O(n)。

由于每次它只生成一个输出(因为我们需要这样做),__next__ 因此每次将生成1个单位成本。

我可以对此进行解释吗

python generator time-complexity space-complexity

0
推荐指数
1
解决办法
49
查看次数