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

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by adam291086
0

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

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.