On 3 February 2015 at 01:44, Rob Cliffe
On 02/02/2015 12:48, João Santos wrote:
L = ['foo', 'bar', 'baz'] is syntactic sugar, you can write L = list('foo', 'bar', 'baz')
No you can't (at least not in Python 2.7.3). (A good advertisement for testing your code before publishing it. ) It has to be L = list(('foo', 'bar', 'baz')) which is using a tuple literal.
Well, if something useful comes out of this discussion, maybe it would be an idea to extend list to allow the former syntax naively assumed, list('foo', 'bar', 'baz') similar to what exists for dict(): dict(a=1, b=2, c=3) though there would be excessive ambiguity for a single argument that is an iterable, like list('abc') which gives ['a','b','c'] not ['abc'] and hence a source many mistakes... Well, just a thought, maybe not a good one. I am sure this must have been discussed in the past, and rejected. -Alexander