Trying to remove the nth element
in generator
based on a condition
. For example in the following sample_generator
trying to remove the i+1
element if i > 90
gen_sample = (x for x in [20,1,100,65,30,10,50]) for i , value in enumerate(gen_sample): if value >=90: del gen_sample[i+1]
Error:
TypeError: 'generator' object does not support item deletion
Any suggestions on the work around will be great.
https://stackoverflow.com/questions/67040583/deleting-nth-element-in-generator-python April 11, 2021 at 09:04AM
没有评论:
发表评论