0

Let's say that I have the following list consisting of a set of objects:

people = [("John","Smith"), ("Jane","Doe"), ("Jane","Smith")]

The objects are created via a separate class which has person.getFirstName and person.getLastName defs.

How can I parse the list such that I end up with a separate list of values consisting of

 uniqueNames = ["Smith","Doe"]

1 Answer 1

3

using list comprehension might do what you need:

>>> people = [("John","Smith"), ("Jane","Doe"), ("Jane","Smith")]
>>> uniqueNames = list(set(i[1] for i in people))
>>> uniqueNames
['Smith', 'Doe']
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.