From the re.findall documentation:
If one or more groups are present in the template, return the list of groups; this will be a list of tuples if the template has more than one group.
As long as your regular expression matches the string three times, the group (.*?) empty for the second two matches. If you want to output the other half of the regular expression, you can add a second group:
>>> re.findall(r'\((.*?)\)|(\w)', '(zyx)bc') [('zyx', ''), ('', 'b'), ('', 'c')]
Alternatively, you can delete all groups to get a simple list of strings again:
>>> re.findall(r'\(.*?\)|\w', '(zyx)bc') ['(zyx)', 'b', 'c']
You need to manually remove the brackets.
James Henstridge
source share