Re: [Python-ideas] Add list.join() please

2019-01-28 Thread Anders Hovmöller
Just by the title I thought you meant >>> [1].join([2, 3, 4]) [2, 1, 3, 1, 4] This is what I'd expect on the list class. So -1 for your suggestion but +1 for what I thought you meant before I read the complete mail :) > On 29 Jan 2019, at 02:40, Jamesie Pic wrote: > > Hello, > > During

Re: [Python-ideas] Add list.join() please

2019-01-28 Thread Chris Angelico
On Tue, Jan 29, 2019 at 4:48 PM David Mertz wrote: > In the first case, the object (a heterogenous list) can NEVER support a > .join() method. It's simply the wrong kind of object. Of course, it's right > as far as the basic type system goes, but its deeper (maybe "structural") > type cannot

Re: [Python-ideas] Add list.join() please

2019-01-28 Thread Henry Chen
One could always write str.join('_', ['list', 'of', 'strings']) I'm not advocating for this syntax, but perhaps it is clarifying. Also, a quick search finds this thread from 20 years ago on this very issue: https://mail.python.org/pipermail/python-dev/1999-June/095366.html On Mon, Jan 28, 2019

Re: [Python-ideas] Add list.join() please

2019-01-28 Thread David Mertz
On Tue, Jan 29, 2019, 12:22 AM Brendan Barnwell > What would you expect to happen with this line: > > > > ['foo', b'foo', 37, re.compile('foo')].join('_') > > That problem already exists with str.join though. It's just > currently spelled this way: > > ','.join(['foo', b'foo', 37,

Re: [Python-ideas] Add list.join() please

2019-01-28 Thread Ronie Martinez
If there is a more Pythonic way of joining lists, tuples, sets, etc., it is by using a keyword and not a method. For example, using a keyword, say *joins*: '-' joins ['list', 'of', 'strings'] > This is more readable than using the method join() since you can read this as "dash joins a list of

Re: [Python-ideas] Add list.join() please

2019-01-28 Thread Brendan Barnwell
On 2019-01-28 18:22, David Mertz wrote: On Mon, Jan 28, 2019 at 8:44 PM Jamesie Pic mailto:j...@yourlabs.org>> wrote: ['cancel', name].join('_') This is a frequent suggestion. It is also one that makes no sense whatsoever if you think about Python's semantics. What would you expect to

Re: [Python-ideas] Add list.join() please

2019-01-28 Thread David Mertz
On Mon, Jan 28, 2019 at 8:44 PM Jamesie Pic wrote: > ['cancel', name].join('_') > This is a frequent suggestion. It is also one that makes no sense whatsoever if you think about Python's semantics. What would you expect to happen with this line: ['foo', b'foo', 37,

Re: [Python-ideas] Add list.join() please

2019-01-28 Thread Jamesie Pic
PS: sorry for my silly example, i know that example could also be written f'cancel_{name}', which is awesome, thank you for that ! But for more complex strings I'm trying to avoid: def foo(): return textwrap.dedent(f''' some {more(complex)} {st.ri("ng")} ''').strip() For some

[Python-ideas] Add list.join() please

2019-01-28 Thread Jamesie Pic
Hello, During the last 10 years, Python has made steady progress in convenience to assemble strings. However, it seems to me that joining is still, when possible, the cleanest way to code string assembly. However, I'm still sometimes confused between the different syntaxes used by join methods:

Re: [Python-ideas] kwargs for return

2019-01-28 Thread Thomas Güttler
Wow, thank you very much for all those answers and hints to my message. David opened my eyes with this: Functions return a single value, period. Yes, this means my question is not about a function, it is about assignment. Dictionary unpacking could be used for my use case. Since it does not