Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #85286

Re: meaning of: line, =

References (5 earlier) <mailman.18488.1423127457.18130.python-list@python.org> <54d33aa6$0$13003$c3e8da3$5496439d@news.astraweb.com> <mailman.18491.1423152554.18130.python-list@python.org> <6304fe65-0606-40eb-8732-c9ba9ae168e7@googlegroups.com> <98777b0d-8f6c-4e2d-965f-0ef875e962b0@googlegroups.com>
From Devin Jeanpierre <jeanpierreda@gmail.com>
Date 2015-02-06 05:09 -0800
Subject Re: meaning of: line, =
Newsgroups comp.lang.python
Message-ID <mailman.18507.1423228193.18130.python-list@python.org> (permalink)

Show all headers | View raw


Sorry for late reply, I somehow missed this email.

On Thu, Feb 5, 2015 at 8:59 AM, Rustom Mody <rustompmody@gmail.com> 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. (Of course, Python does have
exceptions...)

-- Devin

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: meaning of: line, = Albert-Jan Roskam <fomcl@yahoo.com> - 2015-02-04 14:38 +0000
  Re: meaning of: line, = Rustom Mody <rustompmody@gmail.com> - 2015-02-04 07:09 -0800
    Re: meaning of: line, = Peter Otten <__peter__@web.de> - 2015-02-04 18:36 +0100
    Re: meaning of: line, = Chris Angelico <rosuav@gmail.com> - 2015-02-05 08:18 +1100
    Re: meaning of: line, = Devin Jeanpierre <jeanpierreda@gmail.com> - 2015-02-05 01:10 -0800
      Re: meaning of: line, = Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-02-05 20:40 +1100
        Re: meaning of: line, = Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-05 09:08 -0700
          Re: meaning of: line, = Rustom Mody <rustompmody@gmail.com> - 2015-02-05 08:45 -0800
            Re: meaning of: line, = Skip Montanaro <skip.montanaro@gmail.com> - 2015-02-05 10:56 -0600
            Re: meaning of: line, = Tim Chase <python.list@tim.thechases.com> - 2015-02-05 11:00 -0600
            Re: meaning of: line, = Rustom Mody <rustompmody@gmail.com> - 2015-02-05 08:59 -0800
              Re: meaning of: line, = Devin Jeanpierre <jeanpierreda@gmail.com> - 2015-02-06 05:09 -0800
                Re: meaning of: line, = Rustom Mody <rustompmody@gmail.com> - 2015-02-06 05:20 -0800
                Re: meaning of: line, = Rustom Mody <rustompmody@gmail.com> - 2015-02-06 06:03 -0800
        Re: meaning of: line, = Tim Chase <python.list@tim.thechases.com> - 2015-02-05 10:21 -0600
        Re: meaning of: line, = Devin Jeanpierre <jeanpierreda@gmail.com> - 2015-02-05 17:12 -0800
        Re: meaning of: line, = Chris Angelico <rosuav@gmail.com> - 2015-02-06 12:17 +1100
          Re: meaning of: line, = Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-02-06 17:52 +1300
      Re: meaning of: line, = Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-02-06 12:30 +1300

csiph-web