[issue23179] New function proposal: string.from_iterable(iterable [, map_function])

Alessio Bogon report at bugs.python.org
Wed Jan 7 00:27:18 CET 2015


New submission from Alessio Bogon:

I would like to suggest a new string function/constructor: 
string.from_iterable(iterable [,map_function])

I think that the behaviour is intuitive: given an iterable, it construct a string using its element by apply a `map_function`, if provided, to each one of them. After that the str() constructor will be applied to each element in any way, to ensure that effectively an iterable of strings is used.

Of course I do not expect that you will accept this patch, but I think this really is a missing piece of the python library.

You can argue that I could just use
"".join(iterable)
but in my opinion there are two problems:
1) if any of the elements of `iterable` is not a `str` instance, it will fail miserably;
2) this is not very pythonic.

This issue is meant to be an idea for the python maintainers, so I did not write the corresponding `Doc/libary/string.rst` documentation, but if you are interested I could do it.

Thank you people for your amazing work.

----------
components: Library (Lib)
files: string.from_iterable.patch
keywords: patch
messages: 233554
nosy: youtux
priority: normal
severity: normal
status: open
title: New function proposal: string.from_iterable(iterable [,map_function])
type: enhancement
versions: Python 3.4, Python 3.5
Added file: http://bugs.python.org/file37619/string.from_iterable.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23179>
_______________________________________


More information about the Python-bugs-list mailing list