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


Ignore:
Timestamp:
Nov 15, 2016, 4:17:01 PM (8 years ago)
Author:
lfita
Message:

Adding `lstring_values': Function to provide a new list-string from a string which is a list of word separated by a character if some values are repeated they are not included

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r1326 r1328  
    7474# list_differences: Function to provide the differences between two lists
    7575# list_norepeatcombos: Function to all possible (Num-1)-combinations of a Num values without repetitions
     76# lstring_values: Function to provide a new list-string from a string which is a list of word separated by a character if some values
     77#   are repeated they are not included
    7678# multi_index_mat: Function to provide the multiple coordinates of a given value inside a matrix
    7779# num_chainSnum: Function to pass a value to a `ChainStrNum' number
     
    1047110473    return
    1047210474
     10475def lstring_values(liststring,sepchar,finalchar):
     10476    """ Function to provide a new list-string from a string which is a list of word separated by a character if some values
     10477      are repeated they are not included
     10478      liststring= string of [sepchar] separated list of words
     10479      sepchar= original character used to separate different words
     10480      finalchar= final character used to separated values at the resultant string
     10481      >>> lstring_values('tas-tas','-',':')
     10482      tas
     10483      >>> lstring_values('tturb-xmean-last@tturb-xmean-last','@','-')
     10484      tturb-xmean-last
     10485    """
     10486    fname = 'lstring_values'
     10487
     10488    words = liststring.split(sepchar)
     10489    newwords = []
     10490    for word in words:
     10491        if not searchInlist(newwords,word): newwords.append(word)
     10492
     10493    newstring = finalchar.join(newwords)
     10494
     10495    return newstring
     10496
    1047310497#quit()
    1047410498
Note: See TracChangeset for help on using the changeset viewer.