lists

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Nov 2008
Posts: 58
Reputation: adam291086 is an unknown quantity at this point 
Solved Threads: 0
adam291086 adam291086 is offline Offline
Junior Poster in Training

lists

 
0
  #1
Jul 12th, 2009
i currently have this nested list

[[u'Alice Mee', 3], [u'Alice Mee', 4], [u'adam plowman', 1], [u'james pirret', 2]]


I need to remove the last number from each list so i have something like

[[u'Alice Mee'], [u'Alice Mee'], [u'adam plowman'], [u'james pirret']]

the list is populated dynamically and will always change size, therefore the removeal method needs to be dynamic to
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 1,607
Reputation: scru has a spectacular aura about scru has a spectacular aura about 
Solved Threads: 130
Featured Poster
scru's Avatar
scru scru is offline Offline
Posting Virtuoso

Re: lists

 
0
  #2
Jul 12th, 2009
This method is probably a bit less efficient than other suggestions you'll get, but it's just one line:

  1. new_list = [item[:1] for item in old_list]

Question. Why don't you use tuples instead of lists for the inner structure? They use less memory than lists.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 58
Reputation: adam291086 is an unknown quantity at this point 
Solved Threads: 0
adam291086 adam291086 is offline Offline
Junior Poster in Training

Re: lists

 
0
  #3
Jul 12th, 2009
works well, thanks
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC