I want to filter a string like this : 'Hello%World' ----> List = ['Hello','World'] Is there any built-in function for this?.
2 Answers
You could use str.split:
>>> strs='Hello%World'
>>> strs.split("%")
['Hello', 'World']
help(str.split):
S.split(sep=None, maxsplit=-1) -> list of strings
Return a list of the words in S, using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done. If sep is not specified or is None, any whitespace string is a separator and empty strings are removed from the result.
Comments
simply split
str ='Hello%World'
print str.split("%")
gives you
>>>
['Hello', 'World']
1 Comment
Ashwini Chaudhary
How's that different from my answer? And don't use
str as a variable name.