Mar-22-2019, 12:03 PM
@snippsat, unfortunately the OP has mixture of strings and nested lists of strings
[ 'New', ['Group Name Details'], ['Group Name'], ...]
, so invoking line.split()
, when line is a list, will lead to an error. I rewrite my solution to be more pythonic:def extract_words(mixture): """Extract words from mixture of words and lists of words. """ result = list() for item in mixture: if isinstance(item, list): for _astring in item: result += _astring.split() else: result += item.split() return result