Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Difference in list output
#7
Of course, and not only I can understand but especially I can learn.

Your help to both was relevant and clear, thank you for your concern. Clap

But in my answer (#3) I try to explain the reading of the code, when I read or write it, from a semantic point of view.
To make the difference, for example, between [tt for _ in range(4)] and [[0,1] for _ in range(4)] which gives different results.

I try to explain it as follows: in both cases we create a list of lists by iteration [... for _ in range(4)].
In the case with tt, the copied list is a variable that contains a list, which is why tt is not re-evaluated at each iteration, because it refers to the list that has been assigned to it and will give n copy with the same reference.
In the other ([0,1]) it is the literal expression of a list that contains two elements, this is the reason why [0,1] is re-evaluated at each iteration and which will give n independent copy therefore with different references.

In reading or writing the code the difference to be identified between [tt for _ in range(4)] and [[0,1] for _ in range(4)] is tt & [0,1], variable against literal form in list of lists creation by itération.
And of course we cannot identify this differences if we have not understood it and observed it.
Reply


Messages In This Thread
Difference in list output - by OokaydO - Nov-05-2019, 08:44 PM
RE: Difference in list output - by ichabod801 - Nov-05-2019, 09:14 PM
RE: Difference in list output - by OokaydO - Nov-08-2019, 10:20 AM
RE: Difference in list output - by perfringo - Nov-08-2019, 01:18 PM
RE: Difference in list output - by OokaydO - Nov-08-2019, 02:48 PM
RE: Difference in list output - by ichabod801 - Nov-08-2019, 03:21 PM
RE: Difference in list output - by OokaydO - Nov-09-2019, 12:33 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  difference between forms of input a list to function akbarza 6 1,093 Feb-21-2024, 08:02 PM
Last Post: bterwijn
  Output difference from 2 lists of different sizes with words gracenz 5 1,355 Sep-02-2022, 05:09 PM
Last Post: Larz60+
  set.difference of two list gives empty result wardancer84 4 1,528 Jun-14-2022, 01:36 PM
Last Post: wardancer84
  sum() list from SQLAlchemy output Personne 5 4,509 May-17-2022, 12:25 AM
Last Post: Personne
  What is the difference between a generator and a list comprehension? Pedroski55 2 2,244 Jan-02-2021, 04:24 AM
Last Post: Pedroski55
  How to append to list a function output? rama27 5 6,782 Aug-24-2020, 10:53 AM
Last Post: DeaD_EyE
  json.dumps list output qurr 12 5,298 Apr-08-2020, 10:13 PM
Last Post: micseydel
  If item in list = true, Output = xx kroh 0 1,504 Feb-19-2020, 09:17 AM
Last Post: kroh
  output list reducing each time through loop 3Pinter 6 3,542 Mar-19-2019, 01:31 PM
Last Post: perfringo
  os.popen output to a list .. evilcode1 1 5,342 Oct-02-2018, 08:42 PM
Last Post: ODIS

Forum Jump:

User Panel Messages

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