On Thursday, February 5, 2015 at 10:15:29 PM UTC+5:30, Rustom Mody wrote: > On Thursday, February 5, 2015 at 9:39:27 PM UTC+5:30, Ian wrote: > > On Thu, Feb 5, 2015 at 2:40 AM, Steven D'Aprano wrote: > > > Devin Jeanpierre wrote: > > > > > >> On Wed, Feb 4, 2015 at 1:18 PM, Chris Angelico wrote: > > >>> On Thu, Feb 5, 2015 at 4:36 AM, Peter Otten wrote: > > >>>> Another alternative is to put a list literal on the lefthand side: > > >>>> > > >>>>>>> def f(): yield 42 > > >>>> > > >>>> ... > > >>>>>>> [result] = f() > > >>>>>>> result > > >>>> 42 > > >>> > > >>> Huh, was not aware of that alternate syntax. > > >> > > >> Nor are most people. Nor is Python, in some places -- it seems like > > >> people forgot about it when writing some bits of the grammar. > > > > > > Got an example where you can use a,b but not [a,b] or (a,b)? > > > > >>> def f(a, (b, c)): > > ... print a, b, c > > What the hell is that?! > First I am hearing/seeing it. > Whats it called?
The reason I ask: I sorely miss haskell's pattern matching in python. It goes some way: >>> ((x,y),z) = ((1,2),3) >>> x,y,z (1, 2, 3) But not as far as I would like: >>> ((x,y),3) = ((1,2),3) File "<stdin>", line 1 SyntaxError: can't assign to literal >>> [Haskell] Prelude> let (x, (y, (42, z, "Hello"))) = (1, (2, (42, 3, "Hello"))) Prelude> (x,y,z) (1,2,3) -- https://mail.python.org/mailman/listinfo/python-list