0

I have a list of Full Names, where Forenames and Surnames are seperated by a comma, for example:

Authors = ['Shakespeare, William', 'Dafoe, Daniel', 'Pilcher, Rosamunde']

I need a new list that contains only the Surnames, not the Forenames:

AuthorsSurname = ['Shakespeare', 'Dafoe', 'Pilcher']

How can I get there? I tried to search the Authors list with

        regexAuthors = re.compile(r',$')
        AuthorsSurname = (regexAuthors.findall(Authors))

to match all entries until the comma and create a new list, but it says I cannot use "Authors" as an argument here because it is not a string.

(the linked topic did not help)

Colombo
  • 13
  • 4

1 Answers1

1
Authors = ['Shakespeare, William', 'Dafoe, Daniel', 'Pilcher, Rosamunde']

surname = [val.split(",")[0] for val in Authors]
# ['Shakespeare', 'Dafoe', 'Pilcher']
OneCricketeer
  • 151,199
  • 17
  • 111
  • 216
JAdel
  • 1,133
  • 2
  • 16