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


Ignore:
Timestamp:
Oct 18, 2016, 11:50:40 PM (8 years ago)
Author:
lfita
Message:

Adding `stringS_dictvar': Function to provide a dictionary from a Srting which list of DVs separated [key] [value] couples

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r1197 r1201  
    8686# str_list: Function to obtain a list from a string givin a split character
    8787# str_list_k: Function to obtain a list of types of values from a string giving a split character
     88# stringS_dictvar: Function to provide a dictionary from a Srting which list of DVs separated [key] [value] couples
    8889# stringList_dictKeysVals: Function to provide a dictionary with keys which contain values of lists from a string
    8990# subbasin_point: Function to provide sub-basins given a grid point following a matrix of trips
     
    55175518        print errormsg
    55185519        print '  ' + fname + ': longitude values with shape:', lon.shape,            \
    5519           'is different that latitude values with shape:', lat.shape, '(dif. size) !!'
     5520          'is different than latitude values with shape:', lat.shape, '(dif. size) !!'
    55205521        quit(-1)
    55215522
     
    89738974    return matches, locs
    89748975
    8975 def dictvar_listS(listv, dictv, Dc, DVs):
     8976def dictvar_listS(listv, dictv, Dc=',', DVs=':'):
    89768977    """ Function to provide a Dc string separated list of DVs separated [key] [value] couples following a list of keys
    89778978      listv: list of keys from dictionary to use
     
    90009001
    90019002    return stringv
     9003
     9004def stringS_dictvar(stringv, Dc=',', DVs=':'):
     9005    """ Function to provide a dictionary from a Srting which list of DVs separated [key] [value] couples
     9006      stringv: String with a dictionary content as [key1][DVs][val1][Dc][key2][DVs][Val2][Dc]...
     9007      Sc: character to separate key values
     9008      DVs: character to separate key-value couples
     9009    >>> stringS_dictvar('i:1,iv:4,vii:7',',',':')
     9010    {'i': '1', 'vii': '7', 'iv': '4'}
     9011    """
     9012    fname = 'stringS_dictvar'
     9013    dictv = {}
     9014    for Svals in stringv.split(Dc):
     9015        keyn = Svals.split(DVs)[0]
     9016        valn = Svals.split(DVs)[1]
     9017        dictv[keyn] = valn
     9018
     9019    return dictv
    90029020
    90039021def list_coincidences(listA, listB):
Note: See TracChangeset for help on using the changeset viewer.