Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/cwltool/flatten.py @ 5:9b1c78e6ba9c draft default tip
"planemo upload commit 6c0a8142489327ece472c84e558c47da711a9142"
| author | shellac |
|---|---|
| date | Mon, 01 Jun 2020 08:59:25 -0400 |
| parents | 79f47841a781 |
| children |
comparison
equal
deleted
inserted
replaced
| 4:79f47841a781 | 5:9b1c78e6ba9c |
|---|---|
| 1 from __future__ import absolute_import | |
| 2 | |
| 3 from typing import Any, Callable, List, Text, cast | |
| 4 | |
| 5 # http://rightfootin.blogspot.com/2006/09/more-on-python-flatten.html | |
| 6 | |
| 7 | |
| 8 def flatten(l, ltypes=(list, tuple)): | |
| 9 # type: (Any, Any) -> List[Any] | |
| 10 if l is None: | |
| 11 return [] | |
| 12 if not isinstance(l, ltypes): | |
| 13 return [l] | |
| 14 | |
| 15 ltype = type(l) | |
| 16 l = list(l) | |
| 17 i = 0 | |
| 18 while i < len(l): | |
| 19 while isinstance(l[i], ltypes): | |
| 20 if not l[i]: | |
| 21 l.pop(i) | |
| 22 i -= 1 | |
| 23 break | |
| 24 else: | |
| 25 l[i:i + 1] = l[i] | |
| 26 i += 1 | |
| 27 return cast(Callable[[Any], List[Any]], ltype)(l) |
