Hi David

I see where you are coming from. I find it helps to think of sep.join as a
special case. Here's a more general join, with sep.join equivalent to
genjoin(sep, '', '').

    def genjoin(sep, left, right):
        def fn(items):
            return left + sep.join(items) + right
        return fn

Here's how it works

    genjoin('', '', '')('0123') == '0123'
    genjoin(',', '', '')('0123') == '0,1,2,3'
    genjoin(',', '[', ']')('0123') == '[0,1,2,3]'

All of these examples of genjoin can be thought of as string
comprehensions. But they don't fit into your pattern for a string
comprehension literal.

By the way, one might want something even more general. Sometimes one wants
a fn such that

    fn('') == '[]'
    fn('0') == '[0,]'
    fn('01') == '[0,1,]'

which is again a string comprehension.

I hope this helps.

-- 
Jonathan
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/PFWPDN2XA4VK3K6TALKU4TWRXSML65P5/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to