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


Groups > comp.lang.python > #53284

Re: semicolon at end of python's statements

Date 2013-08-30 09:48 +0200
From Antoon Pardon <antoon.pardon@rece.vub.ac.be>
Subject Re: semicolon at end of python's statements
References (4 earlier) <CAA=1kxR_pT=MsUSSk0v-oij-0hSh0LEYrrP5i+5MukmcYfOGWA@mail.gmail.com> <7wob8gywds.fsf@benfinney.id.au> <7wfvtrkcae.fsf@benfinney.id.au> <5220468E.4070407@rece.vub.ac.be> <CAPTjJmqj8FZq8mNnpP79MvEFHv7DNoeQNQmqSm3E18ahXT0bKA@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.383.1377848892.19984.python-list@python.org> (permalink)

Show all headers | View raw


Op 30-08-13 09:25, Chris Angelico schreef:
> On Fri, Aug 30, 2013 at 5:15 PM, Antoon Pardon
> <antoon.pardon@rece.vub.ac.be> wrote:
>> Op 30-08-13 06:55, Ben Finney schreef:
>>> Ben Finney <ben+python@benfinney.id.au> writes:
>>>
>>>> Fábio Santos <fabiosantosart@gmail.com> writes:
>>>>
>>>>> It is a shame that this is not possible in python. for..if exists in
>>>>> comprehensions and not in regular loops but that would be nice
>>>>> sometimes.
>>>>     for foo in (spam for spam in sequence if predicate(spam)): …
>>>
>>> Better:
>>>
>>>     for foo in filter(predicate, sequence):
>>>         process(foo)
>>
>> Well better in what way? You now have to translate a predicate
>> expression into a predicate function. Which AFAIU was one of
>> the reasons to move away from map/filter to list comprehension.
>>
>> As I understand it, python made a move away from map and filter
>> towards list comprehension. Chris seems to want some of the
>> possibilities that came with that incorporated into the for
>> statement. And your suggestion is to go back to the old kind
>> of filter way.
> 
> No, actually Ben's quite right - assuming the predicate is a simple
> function,

But why should we assume that? Suppose I would like to process all
odd items in a list. A comprehension kind of notation would be

|  for item in lst if item % 2:
|      process items

Which we would have to turn into

|  for item in filter(lambda nr: nr % 2, lst):
|      process items

But AFAIR, one of the driving forces behind the introduction to list
comprehension, and thus a move away from map and filter was to get rid
of the lambda's in this kind of situations.

> of course (Python's lambda notation is a bit clunky for
> comparisons); as of Python 3, filter() is lazy and is pretty much what
> I'm doing here.

Lazy or not, is AFAICS, not a point here.

-- 
Antoon Pardon

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


Thread

Re: semicolon at end of python's statements "Sam Fourman Jr." <sfourman@gmail.com> - 2013-08-28 22:10 -0400
  Re: semicolon at end of python's statements Alister <alister.ware@ntlworld.com> - 2013-08-29 09:39 +0000
    Re: semicolon at end of python's statements Chris Angelico <rosuav@gmail.com> - 2013-08-29 19:52 +1000
    Re: semicolon at end of python's statements Fábio Santos <fabiosantosart@gmail.com> - 2013-08-29 11:02 +0100
    Re: semicolon at end of python's statements Ben Finney <ben+python@benfinney.id.au> - 2013-08-30 08:17 +1000
    Re: semicolon at end of python's statements Chris Angelico <rosuav@gmail.com> - 2013-08-30 08:50 +1000
    Re: semicolon at end of python's statements Ben Finney <ben+python@benfinney.id.au> - 2013-08-30 14:55 +1000
    Re: semicolon at end of python's statements Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-08-30 09:15 +0200
    Re: semicolon at end of python's statements Chris Angelico <rosuav@gmail.com> - 2013-08-30 17:25 +1000
    Re: semicolon at end of python's statements Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-08-30 09:48 +0200
    Re: semicolon at end of python's statements Fábio Santos <fabiosantosart@gmail.com> - 2013-08-30 11:32 +0100
      Re: semicolon at end of python's statements Roy Smith <roy@panix.com> - 2013-08-30 06:53 -0400
        Re: semicolon at end of python's statements Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-08-30 16:14 +0200
        Re: semicolon at end of python's statements Chris Angelico <rosuav@gmail.com> - 2013-08-31 08:18 +1000
      Re: semicolon at end of python's statements Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-31 00:09 +0000
        Re: semicolon at end of python's statements Terry Reedy <tjreedy@udel.edu> - 2013-08-31 01:03 -0400
        Re: semicolon at end of python's statements Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-08-31 10:47 +0300
          Re: semicolon at end of python's statements Paul Rudin <paul.nospam@rudin.co.uk> - 2013-08-31 09:00 +0100
            Re: semicolon at end of python's statements Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-08-31 13:28 +0300
            Re: semicolon at end of python's statements Grant Edwards <invalid@invalid.invalid> - 2013-09-02 14:20 +0000
              Re: semicolon at end of python's statements Tim Chase <python.list@tim.thechases.com> - 2013-09-02 09:45 -0500
                Re: semicolon at end of python's statements Roy Smith <roy@panix.com> - 2013-09-02 10:47 -0400
                Re: semicolon at end of python's statements Tim Chase <python.list@tim.thechases.com> - 2013-09-02 12:58 -0500
                Re: semicolon at end of python's statements Chris Angelico <rosuav@gmail.com> - 2013-09-03 07:07 +1000
        Re: semicolon at end of python's statements Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-09-01 19:58 +0200
        Re: semicolon at end of python's statements Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-09-01 21:58 +0200
          Re: semicolon at end of python's statements Steven D'Aprano <steve@pearwood.info> - 2013-09-02 08:05 +0000
            Re: semicolon at end of python's statements Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-09-02 11:45 +0200
            Re: semicolon at end of python's statements Fábio Santos <fabiosantosart@gmail.com> - 2013-09-02 11:42 +0100
            Re: semicolon at end of python's statements Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-09-02 12:58 +0200
            Re: semicolon at end of python's statements "albert visser" <albert.visser@gmail.com> - 2013-09-02 19:44 +0200
              Re: semicolon at end of python's statements Roy Smith <roy@panix.com> - 2013-09-02 13:53 -0400
                Re: semicolon at end of python's statements Neil Cerutti <neilc@norwich.edu> - 2013-09-03 17:15 +0000
                Re: semicolon at end of python's statements Neil Cerutti <neilc@norwich.edu> - 2013-09-03 20:00 +0000
            Re: semicolon at end of python's statements Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-09-02 17:24 -0400
        Re: semicolon at end of python's statements MRAB <python@mrabarnett.plus.com> - 2013-09-02 00:30 +0100
        Re: semicolon at end of python's statements Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-09-02 10:29 +0200
          Re: semicolon at end of python's statements Steven D'Aprano <steve@pearwood.info> - 2013-09-02 09:52 +0000
            Re: semicolon at end of python's statements Chris Angelico <rosuav@gmail.com> - 2013-09-02 20:14 +1000
              Re: semicolon at end of python's statements Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-02 14:57 +0000
            Re: semicolon at end of python's statements Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-09-02 12:52 +0200
            Re: semicolon at end of python's statements Modulok <modulok@gmail.com> - 2013-09-02 17:17 -0600
              Re: semicolon at end of python's statements Roy Smith <roy@panix.com> - 2013-09-02 19:54 -0400
                Re: semicolon at end of python's statements Modulok <modulok@gmail.com> - 2013-09-02 18:56 -0600

csiph-web