2014-10-30 18:27:36 +00:00
|
|
|
import collections
|
2014-10-30 18:07:41 +00:00
|
|
|
|
2014-10-30 17:49:31 +00:00
|
|
|
def glue(*args, **kwargs):
|
2014-10-30 18:27:36 +00:00
|
|
|
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
|
2014-10-30 17:49:31 +00:00
|
|
|
what_to_glue = list(args)
|
2014-10-30 18:27:36 +00:00
|
|
|
kwargs = collections.OrderedDict(sorted(kwargs.items(), key=lambda t: t[0])) # I dont care what order you submit them in, they will be alphabetical
|
2014-10-30 17:56:05 +00:00
|
|
|
what_to_glue.extend([v for k,v in kwargs.iteritems()]) # Ignore all your keys, because you're doing this wrong anyway
|
2014-10-30 18:27:36 +00:00
|
|
|
what_to_glue = flatten(what_to_glue)
|
2014-10-30 18:30:22 +00:00
|
|
|
what_to_glue = [str(x) for x in what_to_glue]
|
2014-10-30 17:49:31 +00:00
|
|
|
return " ".join(what_to_glue)
|