Python Forum
Are list/dict comprehensions interpreted really sequentially?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Are list/dict comprehensions interpreted really sequentially?
#2
It is not clear what you mean by «interpreted really sequentially».

In certain syntax constructs, Python executes code in a non left-to-right way. For example in
a = x + y if x * y > 2 else x - 1
the test x * y > 2 is executed first, then only one of x + y or x - 1 is executed.

Similarly in comprehension constructs, the for loops iterations are actually set up before the body is executed, but the body appears syntactically before the for loop.
Reply


Messages In This Thread
RE: Are list/dict comprehensions interpreted really sequentially? - by Gribouillis - May-31-2022, 08:24 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  convert this List Comprehensions to loop jacklee26 8 1,672 Oct-21-2022, 04:25 PM
Last Post: deanhystad
  Membership test for an element in a list that is a dict value for a particular key? Mark17 2 1,316 Jul-01-2022, 10:52 PM
Last Post: Pedroski55
  Updating nested dict list keys tbaror 2 1,375 Feb-09-2022, 09:37 AM
Last Post: tbaror
  What type of *data* is the name of a list/tuple/dict, etc? alloydog 9 4,680 Jan-30-2021, 07:11 AM
Last Post: alloydog
  How to call multiple functions sequentially Mayo 2 9,724 Jan-06-2021, 07:37 PM
Last Post: Mayo
Question dict value, how to change type from int to list? swissjoker 3 2,910 Dec-09-2020, 09:50 AM
Last Post: perfringo
  How to remove dict from a list? Denial 7 3,179 Sep-28-2020, 02:40 PM
Last Post: perfringo
  Trouble with converting list , dict to int values! faryad13 7 3,913 Sep-04-2020, 06:25 AM
Last Post: faryad13
  Running scripts and location of saved interpreted user-defined classes and functions leodavinci1990 3 2,647 Aug-25-2020, 03:43 AM
Last Post: micseydel
  Sort a dict in dict cherry_cherry 4 96,413 Apr-08-2020, 12:25 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

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