Python Forum
generator function that yield from a list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
generator function that yield from a list
#5
@snippsat, thanks, but my question is more or less theoretical (please check also the SO)
basically, I ask I ask if we have (pseudocode)
def spam():
    for egg in <SOME LIST/TUPLE OBJECT HERE, e.g. returned by some function or method like str.split()>:
       yield egg
does python evaluate the list/tuple when creating the generator function I.e. create the whole list in memory or it is evaluated lazy only when yield next value. I think it's the later
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

Reply


Messages In This Thread
RE: generator function that yield from a list - by buran - Jun-04-2019, 08:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  yield from akbarza 4 431 Apr-19-2024, 07:58 PM
Last Post: DeaD_EyE
  yield usage as statement or expression akbarza 5 921 Oct-23-2023, 11:43 AM
Last Post: Gribouillis
  Using list comprehension with 'yield' in function tester_V 5 1,349 Apr-02-2023, 06:31 PM
Last Post: tester_V
  Tuple generator, and function/class syntax quazirfan 3 4,001 Aug-10-2021, 09:32 AM
Last Post: buran
  What is the difference between a generator and a list comprehension? Pedroski55 2 2,282 Jan-02-2021, 04:24 AM
Last Post: Pedroski55
  Yield generator weird output Vidar567 8 3,358 Nov-23-2020, 10:59 PM
Last Post: deanhystad
  Creating list of lists from generator object t4keheart 1 2,245 Nov-13-2020, 04:59 AM
Last Post: perfringo
  list call problem in generator function using iteration and recursive calls postta 1 1,985 Oct-24-2020, 09:33 PM
Last Post: bowlofred
  Trying to access next element using Generator(yield) in a Class omm 2 2,034 Oct-19-2020, 03:36 PM
Last Post: omm
  Yield statement question DPaul 6 2,574 Sep-26-2020, 05:18 PM
Last Post: DPaul

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020