How to pick up the elements has similar name in a list?
Question: I have a list:

    
    
    ['15g', 'engout', 'ImpactTphase.py', 'LANL.INI', 'OUTGRAF.TXT', 'OUTPAR.TXT', 'par.bat', 'pargraf1.BAT', 'parphase.py', 'RFFLD000.TBL', 'RFFLD010.TBL', 'sp4.acc', 'Tablplot.log', 'tape2.t2', 'tape3.t3', 'TIMESTEPEMITTANCE185.TBL', 'TIMESTEPEMITTANCE190.TBL', 'TIMESTEPEMITTANCE195.TBL', 'TIMESTEPEMITTANCE200.TBL', 'TIMESTEPEMITTANCE205.TBL', 'TIMESTEPEMITTANCE210.TBL', 'TIMESTEPEMITTANCE215.TBL', 'TIMESTEPEMITTANCE220.TBL', 'TIMESTEPEMITTANCE225.TBL', 'TIMESTEPEMITTANCE230.TBL', 'TIMESTEPEMITTANCE235.TBL', 'TIMESTEPEMITTANCE240.TBL', 'TplotPRF.TXT']
    

In python, how could I pick up the elements has `TIMESTEPEMITTANCE???.TBL`.
Also how I can separate "TIMESTEPEMITTANCE???" into "TIMESTEPEMITTANCE"and
"???"? THanks,


Answer: You can use
[`fnmatch.fnmatch`](https://docs.python.org/3/library/fnmatch.html#fnmatch.fnmatch):

    
    
    >>> lst = [
        '15g', 'engout', 'ImpactTphase.py', 'LANL.INI', 'OUTGRAF.TXT', 'OUTPAR.TXT',
        'par.bat', 'pargraf1.BAT', 'parphase.py', 'RFFLD000.TBL', 'RFFLD010.TBL',
        'sp4.acc', 'Tablplot.log', 'tape2.t2', 'tape3.t3', 'TIMESTEPEMITTANCE185.TBL',
        'TIMESTEPEMITTANCE190.TBL', 'TIMESTEPEMITTANCE195.TBL', 'TIMESTEPEMITTANCE200.TBL',
        'TIMESTEPEMITTANCE205.TBL', 'TIMESTEPEMITTANCE210.TBL', 'TIMESTEPEMITTANCE215.TBL',
        'TIMESTEPEMITTANCE220.TBL', 'TIMESTEPEMITTANCE225.TBL', 'TIMESTEPEMITTANCE230.TBL',
        'TIMESTEPEMITTANCE235.TBL', 'TIMESTEPEMITTANCE240.TBL', 'TplotPRF.TXT'
    ]
    >>> import fnmatch
    >>> [x for x in lst if fnmatch.fnmatch(x, 'TIMESTEPEMITTANCE???.TBL')]
    ['TIMESTEPEMITTANCE185.TBL',
     'TIMESTEPEMITTANCE190.TBL',
     'TIMESTEPEMITTANCE195.TBL',
     'TIMESTEPEMITTANCE200.TBL',
     'TIMESTEPEMITTANCE205.TBL',
     'TIMESTEPEMITTANCE210.TBL',
     'TIMESTEPEMITTANCE215.TBL',
     'TIMESTEPEMITTANCE220.TBL',
     'TIMESTEPEMITTANCE225.TBL',
     'TIMESTEPEMITTANCE230.TBL',
     'TIMESTEPEMITTANCE235.TBL',
     'TIMESTEPEMITTANCE240.TBL']
    

For the second question, if you mean to extract digits part out of the string:

You can use the string slice because the pattern is fixed:

    
    
    >>> 'TIMESTEPEMITTANCE185.TBL'[17:20]
    '185'
    

or, you can use
[`filter`](https://docs.python.org/3/library/functions.html#filter) with
[`str.isdigit`](https://docs.python.org/3/library/stdtypes.html#str.isdigit)
(`''.join` is not required if you use Python 2.x)

    
    
    >>> ''.join(filter(str.isdigit, 'TIMESTEPEMITTANCE185.TBL'))
    '185'
    

or, using regular expression:

    
    
    >>> import re
    >>> re.search(r'\d+', 'TIMESTEPEMITTANCE185.TBL').group()
    '185'
    

