Changeset 1004 in lmdz_wrf


Ignore:
Timestamp:
Aug 11, 2016, 12:12:00 PM (8 years ago)
Author:
lfita
Message:

Adding `search_sec_list': Function to provide the values and indices on a list which matches a section of a string

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r1003 r1004  
    5252# radius_angle: Function to generate a matrix with the angle at a given point
    5353# radius_dist: Function to generate a matrix with the distance at a given point
     54# search_sec_list: Function to provide the values and indices on a list which matches a section of a string
    5455# significant_decomposition: Function to decompose a given number by its signifcant potencies
    5556# singleline_printing_class: Function to print all the values of a given class in a single line to be parseavel
     
    82858286        sys.stdout = self._stdout
    82868287
     8288def search_sec_list(listv,sec):
     8289    """ Function to provide the values and indices on a list which matches a section of a string
     8290      listv= list to find matches
     8291      sec= section to search for
     8292    >>> romlist = ['i', 'ii', 'iii', 'iv', 'v', 'vi', 'vii', 'viii', 'ix', 'x', 'xi']
     8293    >>> search_sec_list(romlist,'ii')
     8294    (['ii', 'iii', 'vii', 'viii'], [1, 2, 6, 7])
     8295    """
     8296    fname = 'search_sec_list'
     8297
     8298    matches = []
     8299    locs = []
     8300    il = 0
     8301    for string in listv:
     8302        if string.find(sec) != -1:
     8303            matches.append(string)
     8304            locs.append(il)
     8305        il = il + 1
     8306
     8307    return matches, locs
     8308
    82878309#quit()
    82888310
Note: See TracChangeset for help on using the changeset viewer.