Probably simple syntax error

John Machin sjmachin at lexicon.net
Mon Jul 2 19:49:39 EDT 2007


On Jul 3, 9:04 am, Dustin  MacDonald <dmacdonal... at gmail.com> wrote:

> And Cameron: Ah, yes. It does reduce the confusion. I do know that
> square brackets are used for *creating* a dictionary (blah = ["A",
> "B", "C"],

That's a list, not a dictionary.

> so I figured the same would apply to accessing it (which is
> why for my list, which I created with parenthesis I assumed I accessed
> with parenthesis).

If you created it with parentheses, it's not a list, it's a tuple.
Problem 10: Tuples are immutable.
    atuple[index_variable] = something
and
    atuple.append(something)
will fail.

Print this, cut it out, and paste it inside your hat:
"""
alist = ['foo', 42, True, 123.456]
assert alist[1] == 42

atuple = ('foo', 42, True, 123.456)
assert atuple[1] == 42

adict = {'bar': 'foo', 1: 42, 'abool': True, 'afloat': 123.456}
assert adict[1] == 42
"""

and, in general:

Abjure guesswork, read the documentation!




More information about the Python-list mailing list