I have data in one field that looks like this 1 - EV-32818RC and it ranges with the first number reaching at max 74031 - EV-33160RC. What I am needing is the numbers before the hyphen cut and moved to another Field, only leaving behind the EV-*******. Both fields are text if that helps any.
Solved! Go to Solution.
I would use split()
field.split()[0] for the first part and field.split()[-1] for the last part, assuming there is always a space before and after the hyphen.
I would use split()
field.split()[0] for the first part and field.split()[-1] for the last part, assuming there is always a space before and after the hyphen.
yes there is a space around the hyphen(both sides). This solution worked perfectly, I would like to understand the semantics behind how it worked. Like why [0] and [-1]
split() creates a list of the strings using whitespace as the default separator.
"74031 - EV-33160RC" becomes ['74031', '-', 'EV-33160RC']
You access contents of a list using the list index where 0 is the first item and -1 is the last item (The negative means start at the end and go through the list backwards)
field[1] and field [-2] in this case should both yield '-'
Thank you.