flatten
This commit is contained in:
parent
9e68282351
commit
15b0977ab6
@ -17,8 +17,8 @@ You should probably just use [str.join](https://docs.python.org/2/library/stdtyp
|
|||||||
```
|
```
|
||||||
Name Stmts Miss Cover Missing
|
Name Stmts Miss Cover Missing
|
||||||
-------------------------------------
|
-------------------------------------
|
||||||
glue 6 0 100%
|
glue 13 0 100%
|
||||||
tests 17 0 100%
|
tests 20 0 100%
|
||||||
-------------------------------------
|
-------------------------------------
|
||||||
TOTAL 23 0 100%
|
TOTAL 33 0 100%
|
||||||
```
|
```
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
Name Stmts Miss Cover Missing
|
Name Stmts Miss Cover Missing
|
||||||
-------------------------------------
|
-------------------------------------
|
||||||
glue 6 0 100%
|
glue 13 0 100%
|
||||||
tests 17 0 100%
|
tests 20 0 100%
|
||||||
-------------------------------------
|
-------------------------------------
|
||||||
TOTAL 23 0 100%
|
TOTAL 33 0 100%
|
||||||
|
12
glue.py
12
glue.py
@ -1,7 +1,15 @@
|
|||||||
from collections import OrderedDict
|
import collections
|
||||||
|
|
||||||
def glue(*args, **kwargs):
|
def glue(*args, **kwargs):
|
||||||
|
def flatten(l):
|
||||||
|
for el in l:
|
||||||
|
if isinstance(el, collections.Iterable) and not isinstance(el, basestring):
|
||||||
|
for sub in flatten(el):
|
||||||
|
yield sub
|
||||||
|
else:
|
||||||
|
yield el
|
||||||
what_to_glue = list(args)
|
what_to_glue = list(args)
|
||||||
kwargs = OrderedDict(sorted(kwargs.items(), key=lambda t: t[0])) # I dont care what order you submit them in, they will be alphabetical
|
kwargs = collections.OrderedDict(sorted(kwargs.items(), key=lambda t: t[0])) # I dont care what order you submit them in, they will be alphabetical
|
||||||
what_to_glue.extend([v for k,v in kwargs.iteritems()]) # Ignore all your keys, because you're doing this wrong anyway
|
what_to_glue.extend([v for k,v in kwargs.iteritems()]) # Ignore all your keys, because you're doing this wrong anyway
|
||||||
|
what_to_glue = flatten(what_to_glue)
|
||||||
return " ".join(what_to_glue)
|
return " ".join(what_to_glue)
|
||||||
|
4
tests.py
4
tests.py
@ -19,5 +19,9 @@ class GlueTests(unittest.TestCase):
|
|||||||
assert output == "bozo clown"
|
assert output == "bozo clown"
|
||||||
assert "what" not in output
|
assert "what" not in output
|
||||||
|
|
||||||
|
def test_flaten(self):
|
||||||
|
output = glue("why", ["would", ["you", "run"], "these"], "tests")
|
||||||
|
assert output == "why would you run these tests"
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user