A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2001-February/012708.html below:

[Python-Dev] re: for in dict

[Python-Dev] re: for in dict / range literalsGreg Wilson gvwilson@ca.baltimore.com
Tue, 6 Feb 2001 15:18:34 -0500
> > Ka-Ping Yee asked:
> > What would make for-loops easier to present, given this experience?

> Thomas Wouters replied:
> A simpler version of
> 
>   for x in range(len(sequence)):
> 
> obviously :) (a.k.a. 'indexing for') One that gets taught *before* 'if x in
> sequence', preferably. Syntax that stands out against 'x in sequence', but
> makes 'x in sequence' seem very logical if encountered after the first
> syntax. Something like
> 
>   for x over sequence:
>   for x in 0 .. sequence:
>   for each number x in sequence:

Greg Wilson observes:

Maybe we're lucky that range literals didn't make it into the language
after all (and I say this as someone who asked for them).  If we were
using range literals to iterate over sequences by index:

    for x in [0:len(seq)]:

it'd be very hard to unify index-based iteration over all collection
types ('cuz there's no way to write a "range literal" for the keys in
a dict).

I don't like "for x over sequence" --- trying to teach students that
"in" means "the elements of the sequence", but "over" means "the indices
of the sequence" will be hard.  Something like "for x indexing sequence"
would work (very hard to mistake its meaning), but what would you do for
(index,value) iteration?

But hey, at least we're better off than Ruby, where ".." and "..." (double
or triple ellipsis) mean "up to but not including", and "up to and including"
respectively.  Or maybe it's the other way around :-).

Greg



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4