annotate flatten_lines.py @ 317:de23e595bb5c
experiments with line flattening
author |
cat@eee |
date |
Thu, 11 Feb 2010 09:08:22 -0500 |
parents |
|
children |
f44ad8de0d17 |
rev |
line source |
317
|
1 import doctest
|
|
2 def flatten(texts):
|
|
3 '''
|
|
4 >>> flatten([['cow', 'cat'], '', 'fish', ['bird']])
|
|
5 ['cow', 'cat', 'fish', 'bird']
|
|
6 '''
|
|
7 result = []
|
|
8 if isinstance(texts, basestring):
|
|
9 result.extend(texts.splitlines())
|
|
10 else:
|
|
11 for text in texts:
|
|
12 result.extend(flatten(text))
|
|
13 result = [r.strip() for r in result if r.strip()]
|
|
14 return result
|
|
15 doctest.testmod()
|