D
daniel
is there any typical usage that shows their difference?
thanks
daniel
thanks
daniel
Traceback (most recent call last):daniel said:is there any typical usage that shows their difference?d = {}
d[('multi', 'part', 'key')] = 'schnarz'
d[['multi', 'part', 'key']] = 'schnarz'
3t = (1,2,3,4)
t[2]
t = ({},) # tuple with empty dict as its only item
t[0]["foo"] = "bar"
infidel said: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.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.