custom_join function added
It joins elements of a list using a joiner and a final custom joiner
This commit is contained in:
parent
b6f4465880
commit
9fccdcc51c
@ -7,7 +7,7 @@ __author__ = "Davide Testa"
|
|||||||
__email__ = "davide@davte.it"
|
__email__ = "davide@davte.it"
|
||||||
__credits__ = "Marco Origlia"
|
__credits__ = "Marco Origlia"
|
||||||
__license__ = "GNU General Public License v3.0"
|
__license__ = "GNU General Public License v3.0"
|
||||||
__version__ = "1.5.7"
|
__version__ = "1.5.9"
|
||||||
__maintainer__ = "Davide Testa"
|
__maintainer__ = "Davide Testa"
|
||||||
__contact__ = "t.me/davte"
|
__contact__ = "t.me/davte"
|
||||||
|
|
||||||
|
@ -1468,3 +1468,17 @@ def run_aiohttp_server(app, *args, **kwargs):
|
|||||||
loop = asyncio.new_event_loop()
|
loop = asyncio.new_event_loop()
|
||||||
asyncio.set_event_loop(loop)
|
asyncio.set_event_loop(loop)
|
||||||
web.run_app(app, *args, **kwargs)
|
web.run_app(app, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
def custom_join(_list, joiner, final=None):
|
||||||
|
"""Join elements of `_list` using `joiner` (`final` as last joiner)."""
|
||||||
|
_list = list(map(str, _list))
|
||||||
|
if final is None:
|
||||||
|
final = joiner
|
||||||
|
if len(_list) == 0:
|
||||||
|
return ''
|
||||||
|
if len(_list) == 1:
|
||||||
|
return _list[0]
|
||||||
|
if len(_list) == 2:
|
||||||
|
return final.join(_list)
|
||||||
|
return joiner.join(_list[:-1]) + final + _list[-1]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user