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?
#1
In any programming course/books I learned the intro section mentions the sequential
mode of execution of any program (implying at least the sequential way of navigating
through lines in an editor). But I suppose this sequential mode is also valid for
token-by-token processing.
Yet, in Python list and dictionary comprehensions, like
sum([i**2 for i in range(3)]) 
or
results = {n: n ** 2 for n in range(10)} 

the operational part of the for loop (i**2, n ** 2) comes before the definitive.
And it is not sequential. How does this happen in Python?
Reply


Messages In This Thread
Are list/dict comprehensions interpreted really sequentially? - by anata2047 - May-31-2022, 08:08 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,424 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