Changeset 1174 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
Oct 11, 2016, 4:25:59 PM (9 years ago)
Author:
lfita
Message:

Adding `replace_list': Function to replace a value in a given list

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r1146 r1174  
    7272# radius_angle: Function to generate a matrix with the angle at a given point
    7373# radius_dist: Function to generate a matrix with the distance at a given point
     74# replace_list: Function to replace a value in a given list
    7475# same_shape: Function to check if two matrices have the same shape
    7576# search_sec_list: Function to provide the values and indices on a list which matches a section of a string
     
    94909491
    94919492    return latextext
     9493
     9494def replace_list(listv,oldv,newv):
     9495    """ Function to replace a value in a given list
     9496      listv= list of values
     9497      oldv= value to replace
     9498      newv= value to use
     9499    >>> replace_list(range(10),3,'iii')
     9500    [0, 1, 2, 'iii', 4, 5, 6, 7, 8, 9]
     9501    """
     9502    fname = 'replace_list'
     9503
     9504    newlist = list(listv)
     9505    iv = 0
     9506    for vv in listv:
     9507        print iv,vv,type(vv),oldv,vv == oldv
     9508        if vv == oldv: newlist[iv] = newv
     9509        iv = iv + 1
     9510
     9511    return newlist
     9512
    94929513#quit()
    94939514
Note: See TracChangeset for help on using the changeset viewer.