lists <-> tuple
Peter Notebaert
peno at mailme.org
Sat Nov 5 10:47:50 EST 2005
"Jim" <mrmaple at gmail.com> wrote in message
news:1130973892.137886.170410 at f14g2000cwb.googlegroups.com...
>> Tuples or lists for matrix-like functionality?
>
> Use lists. Tuples are meant for small immutable sets of things that go
> together. Lists are more like arrays, and you can assign to one
> existing element if you want.
>
> One exception, is a short vector is often a tuple like (x, y, z) and
> you might want to multiply that vector by your matrix. You can convert
> a tuple to a list with list(aTuple) or back with tuple(aList.)
>
> Even better, take a look at numarray (or numpy or scipy or scipy_core.)
> They all have really nice matrix code and there are C APIs that let
> you manipulate them. Chances are they do everything you're intending
> to implement.
>
> Immutability example:
> tup = ("a", "b", "c")
> tup[1] = "g"
> Traceback (most recent call last):
> File "<input>", line 1, in ?
> TypeError: object does not support item assignment
> lst = ["a", "b", "c"]
> lst[1] = "g"
> lst
> ['a', 'g', 'c']
>
>
> -Jim
>
Thanks!
More information about the Python-list
mailing list