Tuples

skip at pobox.com skip at pobox.com
Thu Dec 15 18:29:50 CET 2005


    Tuvas> Let's say I make a program something like follows:
    Tuvas> x=[]
    Tuvas> x.append([1,2,3])
    Tuvas> x.append([4,5,6])
    Tuvas> print x
    Tuvas> print x[0]
    Tuvas> print x[0][1]
    Tuvas> x[0][1]=5

    Tuvas> Okay, everything works here as expected except the last line. Why
    Tuvas> won't this work?

You didn't say what you expected to happen, but it works just fine for me:

    >>> x = []
    >>> x.append([1,2,3])
    >>> x.append([4,5,6])
    >>> print x
    [[1, 2, 3], [4, 5, 6]]
    >>> print x[0]
    [1, 2, 3]
    >>> print x[0][1]
    2
    >>> x[0][1] = 5
    >>> print x
    [[1, 5, 3], [4, 5, 6]]

Skip



More information about the Python-list mailing list