Changeset 2676 in lmdz_wrf for trunk/tools/generic_tools.py


Ignore:
Timestamp:
Jul 13, 2019, 9:12:40 PM (5 years ago)
Author:
lfita
Message:

Adding:

  • `searchInlist_Strsec': Function to search a value within a section of the Strings in a list
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r2665 r2676  
    214214# same_shape: Function to check if two matrices have the same shape
    215215# search_sec_list: Function to provide the values and indices on a list which matches a section of a string
     216# searchInlist: Function to search a value wihitn a list
     217# searchInlist_Strsec: Function to search a value within a section of the Strings in a list
    216218# shrinkarray_dim: Function to shrink a given array with a vector of True/False along a given dimension
    217219# significant_decomposition: Function to decompose a given number by its signifcant potencies
     
    248250    listname = list
    249251    nameFind = value to find
    250     >>> searInlist(['1', '2', '3', '5'], '5')
     252    >>> searchInlist(['1', '2', '3', '5'], '5')
    251253    True
    252254    """
    253255    for x in listname:
    254256      if x == nameFind:
     257        return True
     258    return False
     259
     260def searchInlist_Strsec(listname, isec, esec, nameFind):
     261    """ Function to search a value within a section of the Strings in a list
     262    listname = list
     263    isec= initial position of the section
     264    esec= ending position of the section (+1 will be added)
     265    nameFind = value to find
     266    >>> searchInlist_Strsec(['101', '102', '103', '104'], 1, 2, '01')
     267    True
     268    """
     269    fname = 'searchInlist_Strsec'
     270
     271    if len(nameFind) != esec-isec+1:
     272        print errmsg
     273        print '  ' + fname + ": wrong name to find: '" + nameFind + "' and section ",\
     274          isec, ', ', esec, ' !!'
     275        print "   length of the name to find: '" + nameFind + "' length=",           \
     276          len(nameFind), ' does not coincide with size of section', esec-isec+1, '!!'
     277        quit(-1)
     278
     279    for x in listname:
     280      if x[isec:esec+1] == nameFind:
    255281        return True
    256282    return False
Note: See TracChangeset for help on using the changeset viewer.