| | |
lists
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Nov 2008
Posts: 58
Reputation:
Solved Threads: 0
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
[[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
This method is probably a bit less efficient than other suggestions you'll get, but it's just one line:
Question. Why don't you use tuples instead of lists for the inner structure? They use less memory than lists.
python Syntax (Toggle Plain Text)
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.
![]() |
Similar Threads
- concatenation of two linked lists (C)
- Help with inline lists for horizontal navigation (HTML and CSS)
- Bug when creating linked lists in Dev C++ (C++)
- Linked Lists (C)
- MERGING LISTS need help with this one (C++)
- C/ Need Help with Linked Lists please (C)
- making sorted lists (was: Help Me!) (C)
- stack of linked lists (C++)
Other Threads in the Python Forum
- Previous Thread: Interrupt a while loop
- Next Thread: Tkinter scrollbars
| Thread Tools | Search this Thread |
accessdenied advanced apache application argv beginner change command csv def dictionary dynamic edit enter event examples file float format function google gui homework import inches input jaunty java keyboard lapse library line lines linux list lists loop microphone mouse movingimageswithpygame mysql newb number numbers numeric obexftp output parameters parsing path phonebook port prime programming projects py2exe pygame pygtk pyopengl python random recursion redirect remote return reverse scrolledtext session simple skinning smtp software sprite statictext stderr string strings syntax table tennis terminal text thread threading time tkinter tlapse trick tuple tutorial ubuntu unicode unit urllib urllib2 variable voip windows wordgame wxpython






