comparison env/lib/python3.7/site-packages/cwltool/flatten.py @ 0:26e78fe6e8c4 draft

"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
author shellac
date Sat, 02 May 2020 07:14:21 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:26e78fe6e8c4
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)