How python uses generators instead of lists
Editor to share with you how to use python generator to replace the list, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Try to use generators instead of lists
# # def my_range (n) is not recommended: I = 0result = [] while I < n:result.append (fn (I)) I + = 1return result # return list # # recommended def my_range (n): I = 0result = [] while I < n:yield fn (I) # use generator instead of list I + = 1 * as far as possible, unless list-specific functions must be used. The above is all the content of the article "how python uses generators instead of lists". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!