Python has a spectacular function splitthat won't let you use a regex or something like that. You can split your line just by callingmy_string.split(delimiter)
After that, python has a function stripthat will remove all spaces from the beginning and end of the line.
[item.strip() for item in my_string.split(',')]
:
>>> import timeit
>>> timeit.timeit('map(str.strip, "QVOD, Baidu Player".split(","))', number=100000)
0.3525350093841553
>>> timeit.timeit('map(stripper, "QVOD, Baidu Player".split(","))','stripper=str.strip', number=100000)
0.31575989723205566
>>> timeit.timeit("[item.strip() for item in 'QVOD, Baidu Player'.split(',')]", number=100000)
0.246596097946167
, comp 33% , .
, , , "", LC. http://www.artima.com/weblogs/viewpost.jsp?thread=98196