0

I have a list like ["Alex Smith", "John Jones/John Jones and Anna Conner", "James O'Brien"]. I'd like to convert it to a list of individual unique individuals: ["Alex Smith", "John Jones", "Anna Conner", "James O'Brien"]. I can use list(set(vector)) to get the uniqueness that I want, but the splitting is giving me a headache.

I looked at Flattening a shallow list in Python and it looked good, but it disggregated down to the indivual letters rather than the combination of first and last names.

Community
  • 1
  • 1
SteveM49
  • 61
  • 1
  • 1
  • 5
  • Please show some code of what you have tried so far and better or more examples of input and desired output. The problem you describe is still too broad and ambiguous. – Cyb3rFly3r May 03 '16 at 00:06
  • Thanks to @TigerhawkT3. His suggestion gave me just what I wanted. – SteveM49 May 07 '16 at 12:56

1 Answers1

2

Pick a delimiter, join on that delimiter, convert all delimiters to that one, split on that delimiter, then use set() as you were planning on to remove the duplicates:

l = ["Alex Smith", "John Jones/John Jones and Anna Conner", "James O'Brien"]
new_set = set('/'.join(l).replace(' and ', '/').split('/'))

Result:

>>> new_set
{"James O'Brien", 'Alex Smith', 'John Jones', 'Anna Conner'}
TigerhawkT3
  • 48,464
  • 6
  • 60
  • 97