Re: [Tutor] Merge a dictionary into a string

2019-03-17 Thread David L Neil
On 18/03/19 6:05 AM, Mats Wichmann wrote: On 3/16/19 11:39 AM, Valerio Pachera wrote: Consider this: import collections d = OrderedDict(a='hallo', b='world') I wish to get a single string like this: 'a "hallo" b "world"' Notice I wish the double quote to be part of the string. In other words I w

Re: [Tutor] Merge a dictionary into a string

2019-03-17 Thread Mats Wichmann
On 3/16/19 11:39 AM, Valerio Pachera wrote: > Consider this: > > import collections > d = OrderedDict(a='hallo', b='world') > > I wish to get a single string like this: > > 'a "hallo" b "world"' > > Notice I wish the double quote to be part of the string. > In other words I want to wrap the val

Re: [Tutor] Merge a dictionary into a string

2019-03-16 Thread Mats Wichmann
On March 16, 2019 5:57:23 PM MDT, Alan Gauld via Tutor 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-str

Re: [Tutor] Merge a dictionary into a string

2019-03-16 Thread Alan Gauld via Tutor
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 th

Re: [Tutor] Merge a dictionary into a string

2019-03-16 Thread Alex Kleider
On 2019-03-16 10:39, Valerio Pachera wrote: Consider this: import collections d = OrderedDict(a='hallo', b='world') I wish to get a single string like this: 'a "hallo" b "world"' Notice I wish the double quote to be part of the string. In other words I want to wrap the value of a and b. I wa

Re: [Tutor] Merge a dictionary into a string

2019-03-16 Thread Peter Otten
Valerio Pachera wrote: > Consider this: > > import collections > d = OrderedDict(a='hallo', b='world') > > I wish to get a single string like this: > > 'a "hallo" b "world"' > > Notice I wish the double quote to be part of the string. > In other words I want to wrap the value of a and b. > >

Re: [Tutor] Merge a dictionary into a string

2019-03-16 Thread Alan Gauld via Tutor
On 16/03/2019 17:39, Valerio Pachera wrote: > I wish to get a single string like this: > > 'a "hallo" b "world"' > > Notice I wish the double quote to be part of the string. > In other words I want to wrap the value of a and b. When dealing with string layouts I tend to go to string formatting.