glue/glue.py
Tyrel Souza 15b0977ab6 flatten
2014-10-30 14:27:36 -04:00

16 lines
669 B
Python

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 = 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)