如何实现像这样的
join()
函数?
>>> separator = [')', '-a', '(']
>>> args = [['-name', '*.py'], ['-type', 'f'], ['-mtime', '0']]
>>> list(join(separator, args))
["-name", "*.py", ")", "-a", "(", "-type", "f", ")", "-a", "(", "-mtime", "0"]
def join(sep, iterable):
iterator = iter(iterable)
yield from next(iterator)
for i in iterator:
yield from sep
yield from i