Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/cwltool/flatten.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
| author | shellac |
|---|---|
| date | Mon, 22 Mar 2021 18:12:50 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:4f3585e2f14b |
|---|---|
| 1 from typing import Any, Callable, List, cast | |
| 2 | |
| 3 # http://rightfootin.blogspot.com/2006/09/more-on-python-flatten.html | |
| 4 | |
| 5 | |
| 6 def flatten(thing, ltypes=(list, tuple)): | |
| 7 # type: (Any, Any) -> List[Any] | |
| 8 if thing is None: | |
| 9 return [] | |
| 10 if not isinstance(thing, ltypes): | |
| 11 return [thing] | |
| 12 | |
| 13 ltype = type(thing) | |
| 14 thing_list = list(thing) | |
| 15 i = 0 | |
| 16 while i < len(thing_list): | |
| 17 while isinstance(thing_list[i], ltypes): | |
| 18 if not thing_list[i]: | |
| 19 thing_list.pop(i) | |
| 20 i -= 1 | |
| 21 break | |
| 22 else: | |
| 23 thing_list[i : i + 1] = thing_list[i] | |
| 24 i += 1 | |
| 25 return cast(Callable[[Any], List[Any]], ltype)(thing_list) |
