[Tutor] Merge a dictionary into a string

Mats Wichmann mats at wichmann.us
Sat Mar 16 21:19:25 EDT 2019


On March 16, 2019 5:57:23 PM MDT, Alan Gauld via Tutor <tutor at python.org> wrote:
>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,

f-strings are great, but a lot of people have to support multiple python versions so they're not a big option for everyone... yet.
-- 
Sent from a mobile device with K-9 Mail. Please excuse my brevity.


More information about the Tutor mailing list