what is the difference between tuple and list?
bruno at modulix
onurb at xiludom.gro
Tue May 16 11:37:11 EDT 2006
infidel wrote:
>>is there any typical usage that shows their difference?
>
>
> I think the general idea is to use lists for homogenous collections and
> tuples for heterogenous structures.
>
> I think the database API provides a good usage that shows their
> differences. When you do cursor.fetchall() after executing a query,
> you get back a list of tuples. Each tuple is one "record" from the
> cursor. "tuple" is even the term used in relational database theory
> when talking about a table row. You shouldn't be able to add or remove
> fields from a query result, so using a tuple is a perfect match for
> this. On the other hand, you can certainly add, delete, or replace
> entire tuples in the result set, so it makes sense to use a list to
> hold the set of tuples.
>
I think you can remove the 'I think' !-)
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"
More information about the Python-list
mailing list