[Python-ideas] Have a "j" format option for lists

Wolfgang Maier wolfgang.maier at biologie.uni-freiburg.de
Wed May 9 09:20:40 EDT 2018


On 05/09/2018 02:39 PM, Facundo Batista wrote:
> This way, I could do:
> 
>>>> authors = ["John", "Mary", "Estela"]
>>>> "Authors: {:, j}".format(authors)
> 'Authors: John, Mary, Estela'
> 
> In this case the join can be made in the format yes, but this proposal
> would be very useful when the info to format comes inside a structure
> together with other stuff, like...
> 
>>>> info = {
> ...   'title': "A book",
> ...   'price': Decimal("2.34"),
> ...   'authors: ["John", "Mary", "Estela"],
> ... }
> ...
>>>> print("{title!r} (${price}) by {authors:, j}".format(**info))
> "A book" ($2.34) by John, Mary, Estela
> 
> What do you think?
> 

For reference (first message of a rather long previous thread): 
https://mail.python.org/pipermail/python-ideas/2015-September/035787.html



More information about the Python-ideas mailing list