looking for some solutions? You are welcome.

SOLVED: python filter string to return a list


I want to filter a given sentence and extract all the string which are surrounded by single quotation marks and return a list.

For example, sample input:

"Welcome to 'Jungle', is a song by American rock band 'Guns N Roses' released in 1987."


['Jungle', 'Guns N Roses']

Explanation: String - "Jungle" is surrounded by single quotation marks, so we need to pick this. Similarly - Guns N Roses. So the output is having 2 strings in its list. Another sample input:

"How are (you, doing today)"



Explanation: We do not have anything between single quotations so this returns empty list. I tried using split function to split by single quotation, but realised that is not the right approach. Can you please help me how to do this in python?

Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots

No comments: