943,694 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 259
  • Python RSS
Jul 12th, 2009
0

lists

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
adam291086 is offline Offline
61 posts
since Nov 2008
Jul 12th, 2009
0

Re: lists

This method is probably a bit less efficient than other suggestions you'll get, but it's just one line:

python Syntax (Toggle Plain Text)
  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.
Featured Poster
Reputation Points: 975
Solved Threads: 140
Posting Virtuoso
scru is offline Offline
1,624 posts
since Feb 2007
Jul 12th, 2009
0

Re: lists

works well, thanks
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
adam291086 is offline Offline
61 posts
since Nov 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Interrupt a while loop
Next Thread in Python Forum Timeline: Tkinter scrollbars





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC