Changeset 999 in lmdz_wrf
- Timestamp:
- Aug 10, 2016, 5:52:38 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r997 r999 55 55 # Str_Bool: Function to transform from a String value to a boolean one 56 56 # str_list: Function to obtain a list from a string givin a split character 57 # stringList_dictKeysVals: Function to provide a dictionary with keys which contain values of lists from a string 57 58 # subbasin_point: Function to provide sub-basins given a grid point following a matrix of trips 58 59 # unitsdsDate: Function to know how many units of time are from a given pair of dates … … 8238 8239 return string 8239 8240 8241 def stringList_dictKeysVals(string,cD=',',cK='@',cV='|'): 8242 """ Function to provide a dictionary with keys which contain values of lists from a string 8243 string= dictionary with the values 8244 cD= character to use to separate keys 8245 cK= character to use to separate keys from their values 8246 cV= character to use to separate the values for each key 8247 >>> stringv = 'Spain@Madrid|Santander|Sevilla|Toledo,France@Paris|Marseille|Tolouse' 8248 >>> dictKeysVals_stringList(stringv) 8249 {'Spain': ['Madrid', 'Santander', 'Sevilla', 'Toledo'], 'France': ['Paris', 'Marseille', 'Tolouse']} 8250 """ 8251 fname = 'stringList_dictKeysVals' 8252 8253 dictv = {} 8254 8255 dvs = string.split(cD) 8256 for dv in dvs: 8257 key = dv.split(cK)[0] 8258 vals = dv.split(cK)[1].split(cV) 8259 8260 dictv[key] = vals 8261 8262 return dictv 8263 8240 8264 #quit() 8241 8265
Note: See TracChangeset
for help on using the changeset viewer.