Python Forum
What is the difference between a generator and a list comprehension?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is the difference between a generator and a list comprehension?
#3
Thanks!

Reading up on the subject, I was led to the difference between yield and return:

Quote:Python3 yield keyword returns a generator to the caller and the execution of the code starts only when the generator is iterated.

Use yield instead of return when the data size is large

Can't really say I grasp this yet, but it's a start!
Reply


Messages In This Thread
RE: What is the difference between a generator and a list comprehension? - by Pedroski55 - Jan-02-2021, 04:24 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  difference between forms of input a list to function akbarza 6 1,230 Feb-21-2024, 08:02 PM
Last Post: bterwijn
  List Comprehension Issue johnywhy 5 676 Jan-14-2024, 07:58 AM
Last Post: Pedroski55
Question mypy unable to analyse types of tuple elements in a list comprehension tomciodev 1 558 Oct-17-2023, 09:46 AM
Last Post: tomciodev
  Using list comprehension with 'yield' in function tester_V 5 1,389 Apr-02-2023, 06:31 PM
Last Post: tester_V
  list comprehension 3lnyn0 4 1,507 Jul-12-2022, 09:49 AM
Last Post: DeaD_EyE
  set.difference of two list gives empty result wardancer84 4 1,606 Jun-14-2022, 01:36 PM
Last Post: wardancer84
  List comprehension used differently coder_sw99 3 1,834 Oct-03-2021, 04:12 PM
Last Post: coder_sw99
  How to invoke a function with return statement in list comprehension? maiya 4 2,995 Jul-17-2021, 04:30 PM
Last Post: maiya
  List comprehension and Lambda cametan 2 2,327 Jun-08-2021, 08:29 AM
Last Post: cametan
  For Loop with List Comprehension muzikman 25 7,089 Dec-18-2020, 10:45 PM
Last Post: muzikman

Forum Jump:

User Panel Messages

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