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

Recommended Answers

All 2 Replies

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.

works well, thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.