Changeset 999 in lmdz_wrf


Ignore:
Timestamp:
Aug 10, 2016, 5:52:38 PM (9 years ago)
Author:
lfita
Message:

Adding `stringList_dictKeysVals': Function to provide a dictionary with keys which contain values of lists from a string

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r997 r999  
    5555# Str_Bool: Function to transform from a String value to a boolean one
    5656# 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
    5758# subbasin_point: Function to provide sub-basins given a grid point following a matrix of trips
    5859# unitsdsDate: Function to know how many units of time are from a given pair of dates
     
    82388239    return string
    82398240
     8241def 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
    82408264#quit()
    82418265
Note: See TracChangeset for help on using the changeset viewer.