[Tutor] Merge a dictionary into a string

Alan Gauld alan.gauld at yahoo.co.uk
Sat Mar 16 19:57:23 EDT 2019


On 16/03/2019 18:44, Peter Otten wrote:
>
> In Python 3.6 and above you can use f-strings:
> 
>>>> d = dict(a="hello", b="world")
>>>> " ".join(f'{k} "{v}"' for k, v in d.items())
> 'a "hello" b "world"'

Cool, I'd missed f-strings. Time for some reading....

Thanks Peter,


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list