Comparing two generators in Python

后端 未结 4 976
离开以前
离开以前 2020-12-16 10:39

I am wondering about the use of == when comparing two generators

For example:

x = [\'1\',\'2\',\'3\',\'4\',\'5\']

gen_1 = (int(ele) for         


        
4条回答
  •  一个人的身影
    2020-12-16 11:01

    Because generators generate their values on-demand, there isn't any way to "compare" them without actually consuming them. And if your generators generate an infinite sequence of values, such an equality test as you propose would be useless.

提交回复
热议问题