Python doesn't allow me to do match.group() with regex?
Question: I wrote a regex in Python to just get the digits from a string. However, when
I run match.group(), it says that the object `list` has no attribute `group`.
What am I doing wrong? My code as typed pasted into the terminal, and the
terminal's response. Thanks.

    
    
    >>> #import regex library
    ... import re
    >>> 
    >>> #use a regex to just get the numbers -- not the rest of the string
    ... matcht = re.findall(r'\d', dwtunl)
    >>> matchb = re.findall(r'\d', ambaas)
    >>> #macht = re.search(r'\d\d', dwtunl)
    ... 
    >>> #just a test to see about my regex
    ... print matcht.group()
    Traceback (most recent call last):
      File "<stdin>", line 2, in <module>
    AttributeError: 'list' object has no attribute 'group'
    >>> print matchb.group()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: 'list' object has no attribute 'group'
    >>> 
    >>> #start defining the final variables
    ... if dwtunl == "No Delay":
    ...     dwtunnl = 10
    ... else:
    ...     dwtunnl = matcht.group()
    ... 
    Traceback (most recent call last):
      File "<stdin>", line 5, in <module>
    AttributeError: 'list' object has no attribute 'group'
    >>> if ambaas == "No Delay":
    ...     ammbaas = 10
    ... else:
    ...     ammbaas = matchb.group()
    ... 
    Traceback (most recent call last):
      File "<stdin>", line 4, in <module>
    AttributeError: 'list' object has no attribute 'group'
    


Answer: `re.findall()` doesn't return a match object (or a list of them), it always
returns a list of strings (or a list of tuples of strings, in the case of
there being more than one capturing group). And a list doesn't have a
`.group()` method.

    
    
    >>> import re
    >>> regex = re.compile(r"(\w)(\W)")
    >>> regex.findall("A/1$5&")
    [('A', '/'), ('1', '$'), ('5', '&')]
    

`re.finditer()` will return an iterator that yields one match object per
match.

    
    
    >>> for match in regex.finditer("A/1$5&"):
    ...     print match.group(1), match.group(2)
    ...
    A /
    1 $
    5 &
    

