Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/cwltool/flatten.py @ 0:d30785e31577 draft
"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author | guerler |
---|---|
date | Fri, 31 Jul 2020 00:18:57 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d30785e31577 |
---|---|
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) |