Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 17th, 2013, 03:14 PM
jackmanjls jackmanjls is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 13 jackmanjls User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 13 m 11 sec
Reputation Power: 0
Issue clearing list

Re:v2.6
I'm in a loop and want to clear list1 after I append to list2.

For example:

list1 = []
list2 = []
for i in range(0, 100)):
list1 .append(var1)
list1 .append(var2)
list2 .append(list1 )

# at this point I want to clear list1 for the next iteration.
# any of the following clears list1 but also clears list2.
# I want list2 to remain untouched.
list1 .pop()
del list1 [:]

# my current work around is to do a list1=[] each iteration but
# that creates another instance of list1 and I don't want that.

Any ideas?

Reply With Quote
  #2  
Old January 17th, 2013, 05:14 PM
dwblas dwblas is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2009
Posts: 313 dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 23 h 14 m 11 sec
Reputation Power: 7
Quote:
my current work around is to do a list1=[] each iteration but that creates another instance of list1
and removes/garbage collects the previous instance leaving one only. You can also do
Code:
## don't use "i" ,"l" or "o" as they look like numbers
for ctr in range(0, 100)):
   list2.append([var1, var2])
##
##   or list comprehension
list2 = [[var1, var2] for ctr in range(100)] 

Last edited by dwblas : January 17th, 2013 at 05:17 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Issue clearing list

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap