This commit is contained in:
Tyrel Souza 2014-10-30 14:27:36 -04:00
parent 9e68282351
commit 15b0977ab6
4 changed files with 20 additions and 8 deletions

View File

@ -17,8 +17,8 @@ You should probably just use [str.join](https://docs.python.org/2/library/stdtyp
```
Name Stmts Miss Cover Missing
-------------------------------------
glue 6 0 100%
tests 17 0 100%
glue 13 0 100%
tests 20 0 100%
-------------------------------------
TOTAL 23 0 100%
TOTAL 33 0 100%
```

View File

@ -1,6 +1,6 @@
Name Stmts Miss Cover Missing
-------------------------------------
glue 6 0 100%
tests 17 0 100%
glue 13 0 100%
tests 20 0 100%
-------------------------------------
TOTAL 23 0 100%
TOTAL 33 0 100%

12
glue.py
View File

@ -1,7 +1,15 @@
from collections import OrderedDict
import collections
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)
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 = flatten(what_to_glue)
return " ".join(what_to_glue)

View File

@ -19,5 +19,9 @@ class GlueTests(unittest.TestCase):
assert output == "bozo clown"
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__':
unittest.main()