[Edu-sig] Brainstorming a new worksheet for 2006

kirby urner kirby.urner at gmail.com
Mon Jan 2 02:04:04 CET 2006


I think because strings are considered *sequences* that they're also
legitimately *collections*. http://docs.python.org/lib/typesseq.html

i.e. it's hard for me to think an object called a "sequence" wouldn't also
be a "collection" (though not all collections are sequences).

's' is a sequence with one element.

iter is supposed to take a "collection" as its argument, and strings may be
fed to iter.

>>> s = iter('a')
>>> s.next()
'a'

Another author who lumps strings with lists as collections is Dave Kuhlman
in Python 101: "Collections are things like strings (arrays of characters),
lists, tuples, and dictionaries."
http://www.rexx.com/~dkuhlman/python_101/python_101.html

Given there's no formal "collection interface" like in Java (a list of
methods any collection must support), I suppose the concept is a little hazy
around the edges in Python world.  "Iterable" is perhaps better defined?

SmallTalk definitely considers strings under the umbrella of collections.

Currently the page reads:

"""
Our first practice sessions involved using Python's primitive objects, such
as different types of number, plus characters. Then we started looking at
collection types, which are designed to organize information in easy-to-use
*data structures*.

Examples of data structures are:

*[a, b, c] # list
{a :1, b :2, c :3} # dictionary
"abc" # string
(a, b, c) # tuple*

Using data structures, we're able to save a lot of information in a
ready-to-use form.
"""

It's a little ambiguous, in that I use the word 'character' but as you point
out, there's no 'character' type as distinct from 'string' in Python.

However, given the 8th grade audience, I think the important thing is just
to get letters mixed in with numbers when we speak of 'types of object'
(they're used to the idea of integers versus floats, plus one kid brought up
complex -- so then we have letters too, and all the stuff you might do with
'em).

...I may reword.  Keep those suggestions coming -- useful thinking on my
end.

Kirby

On 1/1/06, Scott David Daniels <Scott.Daniels at acm.org> wrote:
>
> kirby urner wrote:
> > ...
> > Python:
> >    shell mode
> >    primitive objects vs. collections
> > Collections:
> >    list
> >    dictionary
> >    string
> >    tuple
>
> 'd move string out of Collections.  It cannot have elements of a
> different type (there is no character type), nor is it mutable.
> Better to be more standard and not call it a collection.  Later
> you can say it behaves in some ways like an ordered list of the
> individual characters in the string.
>
> --Scott David Daniels
> Scott.Daniels at Acm.Org
>
> _______________________________________________
> Edu-sig mailing list
> Edu-sig at python.org
> http://mail.python.org/mailman/listinfo/edu-sig
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/edu-sig/attachments/20060101/dd5ca79c/attachment.htm


More information about the Edu-sig mailing list