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


Groups > comp.lang.python > #79961

Re: What for -- for? (was A bug?)

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <joshua.landau.ws@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'else:': 0.03; 'explicit': 0.07; 'subject: -- ': 0.07; 'subject:bug': 0.07; 'indexes': 0.09; 'python': 0.11; 'def': 0.12; 'suggest': 0.14; '"/"': 0.16; 'iteration,': 0.16; 'name):': 0.16; 'subject:?)': 0.16; 'index': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'trying': 0.19; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'message- id:@mail.gmail.com': 0.30; 'yesterday': 0.31; 'file': 0.32; 'quite': 0.32; 'to:name:python-list': 0.33; 'comment': 0.34; 'usual': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'really': 0.36; 'yield': 0.36; 'to:addr:python-list': 0.38; 'anything': 0.39; 'does': 0.39; 'itself': 0.39; 'to:addr:python.org': 0.39; 'show': 0.63; 'name': 0.63; 'more': 0.64; 'different': 0.65; 'introduce': 0.78; "'for'": 0.84; 'compact,': 0.84; 'delegation': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:content-type; bh=BphP8Rh5wGAq4BFj64QAOwJ+upGrNpbfloPff3Bp9sk=; b=zORLb+upFdWQ9Pe7H1x9sabgEE7Qb8XflaLxfzxn/dJq8krmkPCJeVH+VEijORgY6j 21UEm6k7lp669KaTMNCOG9z/8dOBPvNvqzDifs3kumjoSmAreXkaCNyD0YrIDe2XkzKn lbF0VE7KJ+BCRtjYBPTAnTZby7HG3bbjUyh8OUPgSwdQ7PH/AY3Z8DtpcWyMfZsMB/vW uUHE2kq+Fy3kCh1ea8+9M4wFluIgc06Z+wiAq+nXIum/UvjvRq0saqS8F8j737HXenVQ iCwMem3/hGmqoIN+aMG0NHlQQ8ghTSQtPdSAI1K4XdHvp3MFDJydEnxQAPz1FT57D/NM ODYQ==
X-Received by 10.112.137.39 with SMTP id qf7mr20316368lbb.47.1414689756885; Thu, 30 Oct 2014 10:22:36 -0700 (PDT)
MIME-Version 1.0
Sender joshua.landau.ws@gmail.com
In-Reply-To <94e3143a-c9ab-433d-8b3d-6ab296de14d9@googlegroups.com>
References <f491d969-7405-4017-b9c4-e1cb52a70280@googlegroups.com> <m2mof5$hvh$2@dont-email.me> <mailman.15248.1414459811.18130.python-list@python.org> <m2pinn$hum$2@dont-email.me> <94e3143a-c9ab-433d-8b3d-6ab296de14d9@googlegroups.com>
From Joshua Landau <joshua@landau.ws>
Date Thu, 30 Oct 2014 17:21:56 +0000
X-Google-Sender-Auth vYEGh2kz2bLbCI6zWcSXwFwi--I
Subject Re: What for -- for? (was A bug?)
To python-list <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.15328.1414689765.18130.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1414689765 news.xs4all.nl 2841 [2001:888:2000:d::a6]:50758
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:79961

Show key headers only | View raw


On 29 October 2014 03:22, Rustom Mody <rustompmody@gmail.com> wrote:
> Yesterday I was trying to introduce python to some senior computer scientists.
>
> Tried showing a comprehension-based dir-walker vs a for-loop based one:
>
> def dw(p):
>    if isfile(p):
>       return [p]
>    else:
>       return [p] + [c for f in listdir(p) for c in dw(p+'/'+f)]
>
...
>
> Comment to me : "Well this is neat and compact, but it does not add
> anything fundamental (over usual index based for-loops)"
>
> I tried to say that 'for' over general sequences is quite different
> and significantly more powerful than C/Pascal for over indexes +
> explicit indexing.

If you really want to show the generality of iteration, I suggest you
start with iterators:

    def walk(path):
        yield path

        if isdir(path):
            for name in iterdir(path):
                for file in walk(path + "/" + name):
                    yield file

This is fundementally inexpressable with indexes. It also lends itself
to expressing delegation (eg. "yield from walk(path + "/" + name)").

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


Thread

A bug? "umatrp@gmail.com" <trsexgl@gmail.com> - 2014-10-27 09:01 -0700
  Re: A bug? Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2014-10-27 17:17 +0100
  Re: A bug? Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-27 10:26 -0600
  Re: A bug? Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-28 00:36 +0000
    Re: A bug? Rustom Mody <rustompmody@gmail.com> - 2014-10-27 18:12 -0700
      Re: A bug? Chris Angelico <rosuav@gmail.com> - 2014-10-28 12:25 +1100
        Re: A bug? Rustom Mody <rustompmody@gmail.com> - 2014-10-27 19:13 -0700
    Re: A bug? Joshua Landau <joshua@landau.ws> - 2014-10-28 01:29 +0000
      Re: A bug? Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-29 02:17 +0000
        What for -- for?  (was A bug?) Rustom Mody <rustompmody@gmail.com> - 2014-10-28 20:22 -0700
          Re: What for -- for? (was A bug?) Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-10-28 23:16 -0500
          Re: What for -- for? (was A bug?) Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-10-28 23:23 -0500
            Re: What for -- for? (was A bug?) Rustom Mody <rustompmody@gmail.com> - 2014-10-28 21:40 -0700
              Re: What for -- for? (was A bug?) Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-10-28 23:59 -0500
                Re: What for -- for? (was A bug?) Rustom Mody <rustompmody@gmail.com> - 2014-10-28 22:15 -0700
                Re: What for -- for? (was A bug?) Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-10-29 00:39 -0500
                Re: What for -- for? (was A bug?) Rustom Mody <rustompmody@gmail.com> - 2014-10-28 23:11 -0700
                Re: What for -- for? (was A bug?) Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-10-29 01:18 -0500
                Finding way around ABCs (was What for -- for? (was A bug?)) Rustom Mody <rustompmody@gmail.com> - 2014-10-30 10:01 -0700
                Re: Finding way around ABCs (was What for -- for? (was A bug?)) Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-30 11:09 -0600
                Re: Finding way around ABCs (was What for -- for? (was A bug?)) Rustom Mody <rustompmody@gmail.com> - 2014-10-30 10:16 -0700
                Re: Finding way around ABCs (was What for -- for? (was A bug?)) Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-30 11:11 -0600
          Re: What for -- for? (was A bug?) Ben Finney <ben+python@benfinney.id.au> - 2014-10-29 16:27 +1100
          Re: What for -- for? (was A bug?) Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-10-29 00:42 -0500
            Re: What for -- for? (was A bug?) Rustom Mody <rustompmody@gmail.com> - 2014-10-28 22:57 -0700
          Re: What for -- for? (was A bug?) Ben Finney <ben+python@benfinney.id.au> - 2014-10-29 17:02 +1100
          Re: What for -- for? (was A bug?) Joshua Landau <joshua@landau.ws> - 2014-10-30 17:21 +0000
            Re: What for -- for? (was A bug?) Rustom Mody <rustompmody@gmail.com> - 2014-10-30 10:41 -0700

csiph-web