Movatterモバイル変換


[0]ホーム

URL:


[Python-ideas] More classical for-loop

Mikhail Vmikhailwas at gmail.com
Fri Feb 17 11:30:53 EST 2017


On 17 February 2017 at 04:59, Chris Angelico <rosuav at gmail.com> wrote:> On Fri, Feb 17, 2017 at 2:13 PM, Mikhail V <mikhailwas at gmail.com> wrote:> > Common use case:> >> > L = [1,3,5,7]> >> > for i over len(L):> >    e = L[i]> >> > or:> >> > length = len(L)> > for i over length:> >    e = L[i]>> Better use case:>> for i, e in enumerate(L):>>This would be more compact, yet less readable, more error prone variant.I'd avoid it it all costs and even if I don't need the index further inloop body,(which happens rarely in my experience) I write e=L[i] in second lineto make the code more verbose and keep the flow order.So your variant (and those proposed in PEP-212) could serve in listcomprehensions for example, but for common 'expanded' code  I find itdecline of readability, and creating totally different variants for sameiteration idea.But partially that could be simply matter of habit and love to contractions.Mikhail-------------- next part --------------An HTML attachment was scrubbed...URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170217/d47ee376/attachment.html>


More information about the Python-ideasmailing list

[8]ページ先頭

©2009-2026 Movatter.jp