the yield keyword in python

실리콘·2022년 12월 15일
0

python

목록 보기
1/1

Q. Why use lazy iterators?
A. To solve memory issue. use the yield keyword instead or return inside functions
E. Reading a list of large files (~GB) into python list can cause memory issue, so return a lazy iterator, or generator in python, which will lazy load these things when they are needed.

Q. What does generator consists of?
A. some metadata like state of the function, variable binding, instruction pointer, internal stack etc.

For detailed instruction, this link has a good example.

profile
software engineer

0개의 댓글