When I tried to answer this question: regex to separate% ages and values in python , I noticed that I had to reorder the groups from the result to find everything. For instance:
data = """34% passed 23% failed 46% deferred"""
result = {key:value for value, key in re.findall('(\w+)%\s(\w+)', data)}
print(result)
>>> {'failed': '23', 'passed': '34', 'deferred': '46'}
Here's the search result:
>>> re.findall('(\w+)%\s(\w+)', data)
>>> [('34', 'passed'), ('23', 'failed'), ('46', 'deferred')]
Is there a way to change / specify the group order that re.findall returns does :
[('passed', '34'), ('failed', '23'), ('deferred', '46')]
To clarify, the question arises:
Is it possible to refine the order or reorder the groups to return the re.findall function?
I used the above example to create a dictionary to indicate a reason / usage example when you want to reorder (making the key as value and value as key)
Further clarification:
, , , re.search pr re.match. , , findall , . : - , . .