<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Named Groups of Regular Expressions
Make use of regular expressions more readable with named groups.
Step1:  Mackenzie (first name)
Mackenzie (last name)
The Zen of Python, by Tim Peters
Readability counts.
Step2:  Regular expressions can be used to indicate if a string matches a pattern or not.
Regular expressions can also be used to do some parsing.
The substrings of interest are called groups.
The traditional way of referring to a group is by index number.
Python has another way of referring to a group by name.
Using names give both the regular expression
and references to match groups more meaning.
They make Python code more readable.
<ASSISTANT_TASK:>
Python Code:
m.group(2)
m.group('first_name')
Explanation: Named Groups of Regular Expressions
Make use of regular expressions more readable with named groups.
End of explanation
import re
Explanation: Mackenzie (first name)
Mackenzie (last name)
The Zen of Python, by Tim Peters
Readability counts.
End of explanation
foo_pattern = re.compile('''
    ^
    ([A-Za-z]+)
    ,[ ]
    ([A-Za-z]+)
    $
''', re.VERBOSE)
s = 'James, Mackenzie'
m = re.match(foo_pattern, s)
m
m.groups
m.group(0)
m.group(1)
m.group(2)
foo_pattern = re.compile('''
    ^
    (?P<last_name>[A-Za-z]+)
    ,[ ]
    (?P<first_name>[A-Za-z]+)
    $
''', re.VERBOSE)
m = re.match(foo_pattern, s)
m
m.groups
m.group(0)
m.group(1)
m.group(2)
m.group('last_name')
m.group('first_name')
Explanation: Regular expressions can be used to indicate if a string matches a pattern or not.
Regular expressions can also be used to do some parsing.
The substrings of interest are called groups.
The traditional way of referring to a group is by index number.
Python has another way of referring to a group by name.
Using names give both the regular expression
and references to match groups more meaning.
They make Python code more readable.
End of explanation
<END_TASK>