| | |
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
Views: 152 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for Python
anti approximation array avogadro basic beginner builtin cipher clear code color converter countpasswordentry cturtle curved def dictionary drive dynamic examples excel file float format frange ftp function gui heads homework import input java lapse library line lines linux list lists loop mouse multiple mysqldb mysqlquery newb number numbers output parsing path port prime program programming projects py2exe pygame pymailer pyqt python random raw_input recursion recursive redirect script scrolledtext server singleton sqlite ssh stamp string strings subprocess sum syntax table terminal text textarea thread threading time tkinter tlapse tuple tutorial twoup ubuntu unicode urllib urllib2 variable web-scrape wikipedia windows word wxpython






