Changeset 996 in lmdz_wrf
- Timestamp:
- Aug 10, 2016, 1:09:23 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r995 r996 36 36 # dictionary_key: Function to provide the first key in a dictionay with a given value 37 37 # dictionary_key_list: Function to provide the first key in a dictionay of lists with a given value 38 # dictVeysVals_stringList: Function to provide strings from a dictionary with keys which contain values of lists 38 39 # files_folder_HMT: Function to retrieve a list of files from a folder [fold] and files with [head]*[middle]*[tail] 39 40 # get_configuration: Function to get the configuration from an ASCII external file … … 8118 8119 8119 8120 for key in dictv.keys(): 8120 print ' # ' + key + ':', dictv[key]8121 print ' # ' + key + ':', dictv[key] 8121 8122 8122 8123 return … … 8128 8129 M= middle of the key (empty for nothing) 8129 8130 T= tail of the key (empty for nothing) 8130 dictrom = {'i':1, 'ii':2, 'iii':3, 'iv':4, 'v':5, 'vi':6, 'vii':2, 'viii':8, 'ix':9, 'x':10, 'xi':11 }8131 >>> dictrom = {'i':1, 'ii':2, 'iii':3, 'iv':4, 'v':5, 'vi':6, 'vii':2, 'viii':8, 'ix':9, 'x':10, 'xi':11 } 8131 8132 >>> get_specdictionary_HTM(dictrom,H='i') 8132 8133 {'ii': 2, 'ix': 9, 'iii': 3, 'i': 1, 'iv': 4} … … 8207 8208 return newdictv 8208 8209 8209 dictrom = {'i':1, 'ii':2, 'iii':3, 'iv':4, 'v':5, 'vi':6, 'vii':2, 'viii':8, 'ix':9, 'x':10, 'xi':11 } 8210 print get_specdictionary_HMT(dictrom,H='i') 8211 print get_specdictionary_HMT(dictrom,M='i') 8212 print get_specdictionary_HMT(dictrom,T='i') 8213 print get_specdictionary_HMT(dictrom,H='v',M='i') 8214 print get_specdictionary_HMT(dictrom,H='x',T='i') 8215 print get_specdictionary_HMT(dictrom,M='i',T='x') 8216 print get_specdictionary_HMT(dictrom,H='v',M='i',T='i') 8210 def dictVeysVals_stringList(dictv,cD=',',cK='@',cV='|'): 8211 """ Function to provide strings from a dictionary with keys which contain values of lists 8212 dictv= dictionary with the values 8213 cD= character to use to separate keys 8214 cK= character to use to separate keys from their values 8215 cV= character to use to separate the values for each key 8216 >>> dictvals = {'Spain': ['Madrid', 'Santander', 'Sevilla', 'Toledo'], 'France': ['Paris', 'Marseille', 'Tolouse']} 8217 Spain@Madrid|Santander|Sevilla|Toledo,France@Paris|Marseille|Tolouse 8218 """ 8219 fname = 'dictVeysVals_stringList' 8220 8221 ik = 1 8222 for key in dictv.keys(): 8223 if ik == 1: 8224 string = key + cK 8225 else: 8226 string = string + cD + key + cK 8227 8228 iv = 1 8229 for val in dictv[key]: 8230 if iv == 1: 8231 string = string + val 8232 else: 8233 string = string + cV + val 8234 iv = iv + 1 8235 8236 ik = ik + 1 8237 return string 8238 8217 8239 #quit() 8218 8240
Note: See TracChangeset
for help on using the changeset viewer.