Hello everyone, ok so I am working on this code that takes a string and splits it using the re module. The string contains words in between "<" and ">" (sometimes multiple words). Now what the program does is it splits the string using the two characters above. Then it returns a list with the characters that were split along with the rest of the text in the string. After that there is a for loop, the purpose of the loop is to take the the multiple words that were in between the above characters and split them using whitespace.
Here is my code:
def test(): a = "<this is> <a> test" b = re.split("(<|>)", a) for item in b: c = item.split(' ') print c, #Output: [''] ['<'] ['this', 'is'] ['>'] ['', ''] ['<'] ['a'] ['>'] ['', 'test']
As you can see I get the above output however what I want to get is just one list as an output.
['', '<', 'this', 'is', '>', '', '', '<', 'a', '>', '', 'test']
Thanks in advance.