| | |
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 |
address aliased anydbm app bash beginner bits changecolor cipher class clear code conversion coordinates corners cturtle curves definedlines development dictionary dynamic events examples excel external feet file float format ftp function gui handling homework images import info input java keycontrol line linux list lists loan loop matching mouse number numbers output parsing path permissions port prime programming projects py2exe pygame pymailer python random rational raw_input recursion recursive scrolledtext searchingfile shebang singleton split string strings table tails terminal text thread threading time tkinter tlapse tooltip tuple tutorial type ubuntu unicode url urllib urllib2 valueerror variable whileloop windows word wx.wizard wxpython xlwt






