I'm working with a CSV-file, from which I might get multiple values. For example, a file with books, which might have multiple writers, for example {Ben Norrington|Chad Andersson}. They have together written a book.
In my code, I'm using regular expressions to split by the | and take remove the { and the }. It works fine.
The problem comes when I want to return the names of the writers. I only get the first name, not the second. How do I get both?
This is my code that takes a column from the CSV-file. The code is written in python 2.7
def ifseveral(x):
if "{" not in x and "(" not in x and x != "NULL":
return x
elif "{" in x:
splits =""
splits = x.split("|")
for i in splits:
string = i
string = re.sub('[{}]', '', string)
if "(" in string:
splitpar = ""
splited = string.split("(")
splitpar += splited[0][0:]
return splitpar
else:
**return string** #here is the problem
else:
return "No information available"
splitpar = ""; splited = string.split("("); splitpar += splited[0][0:]to justsplitpar = string.split("(")[0].