0

I want to filter a string like this : 'Hello%World' ----> List = ['Hello','World'] Is there any built-in function for this?.

0

2 Answers 2

8

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.

Sign up to request clarification or add additional context in comments.

Comments

0

simply split

str ='Hello%World'
print str.split("%")

gives you

>>> 
['Hello', 'World']

1 Comment

How's that different from my answer? And don't use str as a variable name.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.