Let's say we have a string lie this
so we can do
in this case str.split() will produce a list (i.e. it will generate the whole list in memory)
for same result we can do also
'a b c'
(simplified example)so we can do
spam = 'a b c' for ch in spam.split(' '): print(ch)
in this case str.split() will produce a list (i.e. it will generate the whole list in memory)
for same result we can do also
def chars(eggs): for ch in eggs.split(' '): yield ch spam = 'a b c' for ch in chars(spam): print(ch)in this case the generator function chars will not produce the list from
eggs.split()
in memory, right? it will be evaluated lazy? I started to doubt myself today answering on SO question...
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs