Changeset 605

Show
Ignore:
Timestamp:
07/08/03 15:17:39 (5 years ago)
Author:
sholloway
Message:

Added flatten function

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/RBFoundation/RBFoundation/Utilities.py

    r551 r605  
    5656#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    5757 
     58def flatten(collection, level=1): 
     59    if isIterable(collection): 
     60        if level: 
     61            return [each for item in collection for each in flatten(item, level-1)] 
     62        else: 
     63            return collection 
     64    else: 
     65        return [collection] 
     66 
     67def flattenall(collection): 
     68    return flatten(collection, -1) 
     69 
    5870def cleanupstrlst(datalst, FilterResult=0): 
    5971    """Strips characters from a list of strings, and drops subsequent empty strings.