tuple versus list

bonono at gmail.com bonono at gmail.com
Sun Oct 16 11:08:20 EDT 2005


In this particular case, it seems that (width,height) looks nicer. But
I think otherwise, list constuct is easier to read, even though it is
supposed to be slower.

With list you can :
[a] + [ x for x in something ]

With tuple it looks like this :
(a,) + tuple(x for x in something)

I think the list looks cleaner. And since you cannot concat tuple with
list, I think unless it looks obvious and natural(as in your case), use
list.

Xah Lee wrote:
> suppose i'm going to have a data structure like this:
>
> [
> [imgFullPath,(width, height)],
> [imgFullPath,(width, height)],
> [imgFullPath,(width, height)],
> [imgFullPath,(width, height)],
> ...
> ]
>
> should i use (width,height) or [width,height]?
> what advantage i get to use n-tuple instead of the generic list?
> 
> Thanks.
> 
>  Xah
>  xah at xahlee.org
>http://xahlee.org/




More information about the Python-list mailing list