Lists and Tuples

Ron Adam radam2 at tampabay.rr.com
Sat Dec 6 10:44:49 EST 2003


On Fri, 5 Dec 2003 16:59:57 +1100, Andrew Bennetts
<andrew-pythonlist at puzzling.org> wrote:

>On Fri, Dec 05, 2003 at 05:19:33AM +0000, Jeff Wagner wrote:
>> I've spent most of the day playing around with lists and tuples to get a really good grasp on what
>> you can do with them. I am still left with a question and that is, when should you choose a list or
>> a tuple? I understand that a tuple is immutable and a list is mutable but there has to be more to it
>> than just that.  Everything I tried with a list worked the same with a tuple. So, what's the
>> difference and why choose one over the other?
>
>What's the difference?
>


Items in lists and not in tuples:


>>>> import sets
>>>> sets.Set(dir(list)).difference(sets.Set(dir(tuple)))
>Set(['sort', 'index', '__delslice__', 'reverse', 'extend', 'insert',
>'__setslice__', 'count', 'remove', '__setitem__', '__iadd__', 'pop',
>'__delitem__', 'append', '__imul__'])
>
>;)
>
>-Andrew.
>


And Items in tuples and not in lists:

>>> sets.Set(dir(tuple)).difference(sets.Set(dir(list)))
Set(['__getnewargs__'])



Items in both tuples and lists:

>>> sets.Set(dir(tuple)).intersection(sets.Set(dir(list)))
Set(['__getslice__', '__str__', '__getattribute__', '__rmul__',
'__lt__', '__init__', '__setattr__', '__reduce_ex__', '__new__',
'__contains__', '__class__', '__doc__', '__len__', '__mul__',
'__ne__', '__getitem__', '__reduce__', '__iter__', '__add__',
'__gt__', '__eq__', '__delattr__', '__le__', '__repr__', '__hash__',
'__ge__'])



Maybe someone could tell me how and/or when  __getnewargs__ is used?


_Ronald Adam






More information about the Python-list mailing list