I'm trying to write a function that will allow me to pass in a string and a character to split the string by.
This obviously works:
def delimit(inputValue, splitChar):
splitValue = [x.strip() for x in inputValue.split(',')]
print(splitValue)
delimit('100, 200,300 ,400,500',',')
Printing this:
['100', '200', '300', '400', '500']
But when I try to use a variable to specify the delimiting value, it doesn't work:
def delimit(inputValue, splitChar):
splitChar = "'" + splitChar + "'"
splitValue = [x.strip() for x in inputValue.split(splitChar)]
print(splitValue)
delimit('100, 200,300 ,400,500',',')
Which returns:
['100, 200,300 ,400,500']
Is it possible to use a variable inside of split()? If so, how would I accomplish this?