Python Forum
output list reducing each time through loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
output list reducing each time through loop
#4
Hey Buran,

Super interesting article and it explained a lot to me. However I don't get a tiny thing: lists are mutable, okay. And therefor doing this:

start = [1,2,3,4,5]
new = []
t = True
for s in start:
    new.append(start)
    if t:
    	start.pop(0)
        t = False
print(new)
"new" will output [2,3,4,5] a few times. As expected.

But since lists are mutable I would expect that changing "start" to a new definition would alter the "new" list as well.

start = [1,2,3,4,5]
new = []
t = True
for s in start:
    new.append(start)
    if t:
    	start.pop(0)
        t = False
start = ["test"]
print(new)
But python will still output [2,3,4,5] a few times.

Why doesn't it output "test" a few times?
Reply


Messages In This Thread
RE: output list reducing each time through loop - by 3Pinter - Mar-19-2019, 10:25 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  sum() list from SQLAlchemy output Personne 5 4,601 May-17-2022, 12:25 AM
Last Post: Personne
  Reducing runtime memory usage in Cpython interpreter david_the_graower 2 2,269 Oct-18-2021, 09:56 PM
Last Post: david_the_graower
  Real-Time output of server script on a client script. throwaway34 2 2,099 Oct-03-2021, 09:37 AM
Last Post: ibreeden
  Reducing JSON character count in Python for a Twitter Bot johnmitchell85 2 59,028 Apr-28-2021, 06:08 PM
Last Post: johnmitchell85
  How to measure execution time of a multithread loop spacedog 2 2,929 Apr-24-2021, 07:52 AM
Last Post: spacedog
  Time.sleep: stop appending item to the list if time is early quest 0 1,903 Apr-13-2021, 11:44 AM
Last Post: quest
  concatenating 2 items at a time in a python list K11 3 2,414 Oct-21-2020, 09:34 AM
Last Post: buran
  fraction module: can you stop the reducing? qmfoam 1 2,447 Oct-10-2020, 06:10 PM
Last Post: bowlofred
  using 'while loop' output going into infinite loop... amitkb 2 2,009 Oct-05-2020, 09:18 PM
Last Post: micseydel
  Appending list Trouble Big Time Milfredo 7 3,213 Oct-01-2020, 02:59 AM
Last Post: Milfredo

Forum Jump:

User Panel Messages

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