On Friday, February 6, 2015 at 6:40:23 PM UTC+5:30, Devin Jeanpierre wrote: > Sorry for late reply, I somehow missed this email. > > On Thu, Feb 5, 2015 at 8:59 AM, Rustom Mody wrote: > > 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) > > Yeah, but Haskell is ludicrous. > > Prelude> let (x, 2) = (1, 3) > Prelude> > > Only non-falsifiable patterns really make sense as the left hand side > of an assignment in a language without exceptions, IMO. Otherwise you > should use a match/case statement.
Which is what people do 99% of the times - write pattern matching function defs I was just writing a 1 liner showing matching of constants and variables simultaneously -- https://mail.python.org/mailman/listinfo/python-list