Solved! Go to Solution.
def FindLabel ( [Name] ): Split = [Name].split(",") Split = Split[0] #drops everything after comma Split = Split.split("-") #splits by the hyphen if len(Split) == 2: expression = Split[0] + "- \n" + Split[1] return expression elif len(Split) == 3: expression = Split[0] + "-" + Split[1] + "- \n" + Split[2] return expression else: return Split[0]
Likewise mine labelled all the samples. It will only work if there are 3 or less cities names in the name field.
I like yours Sol, except it splits single names in half, I think those ones would be fine on one line, but I guess its not my call.
def FindLabel ( [Name] ): Split = [Name].split(",") Split = Split[0] #drops everything after comma Split = Split.split("-") #splits by the hyphen if len(Split) == 2: expression = Split[0] + "- \n" Split[1] elif len(Split) == 3: expression = Split[0] +"-" + Split[1] + "- \n" + Split[2] return expression
def FindLabel ( [Name] ): Split = [Name].split(",") Split = Split[0] #drops everything after comma Split = Split.split("-") #splits by the hyphen if len(Split) == 2: expression = Split[0] + "- \n" + Split[1] elif len(Split) == 3: expression = Split[0] +"-" + Split[1] + "- \n" + Split[2] return expression
def FindLabel ( [Name] ): Split = [Name].split(",") Split = Split[0] #drops everything after comma Split = Split.split("-") #splits by the hyphen if len(Split) == 2: expression = Split[0] + "- \n" + Split[1] return expression elif len(Split) == 3: expression = Split[0] +"-" + Split[1] + "- \n" + Split[2] return expression
def FindLabel ( [Name] ): Split = [Name].split(",") Split = Split[0] #drops everything after comma Split = Split.split("-") #splits by the hyphen if len(Split) == 2: expression = Split[0] + "- \n" + Split[1] return expression elif len(Split) == 3: expression = Split[0] +"-" + Split[1] + "- \n" + Split[2] return expression