Re: Report on non-breaking spaces in posts (was: How to join elements at the beginning and end of the list)

2017-10-31 Thread Jon Ribbens
On 2017-10-31, Stefan Ram wrote: > Ned Batchelder writes: >>     def wrapped_join(values, sep): > > Ok, here's a report on me seing non-breaking spaces in > posts in this NG. I have written this report so that you > can see that it's not my newsreader that is converting > something, b

Re: How to join elements at the beginning and end of the list

2017-10-31 Thread Steve D'Aprano
On Wed, 1 Nov 2017 02:29 am, Neil Cerutti wrote: > You can use the % operator instead of +, and a generator > expression instead of map. It's a pretty small improvement, > though. > > values = '||%s||' % ('||'.join(str(s) for s in value_list)) > > At least... I THINK you can use that generator e

Re: How to join elements at the beginning and end of the list

2017-10-31 Thread Ned Batchelder
On 10/31/17 12:29 PM, Stefan Ram wrote: Ned Batchelder writes: However you solve it, do yourself a favor and write a function to encapsulate it: It is always a good solution to encapsulate a pattern into a function. So I agree that this is a good suggestion. But just for the sole sake

Re: How to join elements at the beginning and end of the list

2017-10-31 Thread Neil Cerutti
On 2017-10-31, Stefan Ram wrote: > Neil Cerutti writes: >>You can use the % operator instead of +, and a generator >>expression instead of map. It's a pretty small improvement, >>though. > > "Improvement" in what sense? > > C:\>python -m timeit -s "value_list = [1, 2, 3, 4, 56, 's']" "values =

Re: How to join elements at the beginning and end of the list

2017-10-31 Thread Ned Batchelder
On 10/31/17 11:29 AM, Neil Cerutti wrote: On 2017-10-31, Ganesh Pal wrote: Here is my solution values = '||' + '||'.join(map(str, value_list)) + '||' values '||1||2||3||4||56||s||' I am joining the elements at the beginning and end of the list using '+' operator any other solution, this is

Re: How to join elements at the beginning and end of the list

2017-10-31 Thread Neil Cerutti
On 2017-10-31, Ganesh Pal wrote: > Here is my solution > values = '||' + '||'.join(map(str, value_list)) + '||' values > > '||1||2||3||4||56||s||' > > I am joining the elements at the beginning and end of the list > using '+' operator any other solution, this is not looking > neater > >

How to join elements at the beginning and end of the list

2017-10-31 Thread Ganesh Pal
How to join each elements with a delimiter at (1) beginning and end of the list and (2) connecting all elements of the list Example : >>> value_list = [1, 2, 3, 4, 56, 's'] I want this to be converted in this from '||1||2||3||4||56||s||' Here is my solution >>> values = '||' + '||'.join(ma