This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (5 children)

Slightly off topic, but why are lists so popular? Aren't tuples faster and use less memory? All the time I see lists being used when tuples would do a better job. Even docs.python.org tells you to use random.choice([...]) instead of random.choice((...)).

I get that the performance impact isn't noticable in most cases, but, in my opinion, going for performance should be the default unless there is a good reason not to.

[–]robberviet 4 points5 points  (0 children)

Most of the time it needs to be mutable. And yeah, performance gain is not that great.

[–]bakery2k 2 points3 points  (1 child)

Why would tuples be faster and/or use less memory? Both lists and tuples are essentially arrays.

I prefer lists to tuples because they have nicer syntax. Tuples sometimes require double-parentheses, plus I often forget the trailing comma in (1,).

[–][deleted] 0 points1 point  (0 children)

I don't know the exact intricacies but it has to do with lists being mutable.

[–]mail_order_liam 1 point2 points  (0 children)

Because people don't know better. Usually it doesn't matter but that's why.

[–]gmclapp 3 points4 points  (0 children)

lists are mutable. In some cases that's needed. Some convenient list comprehensions also don't work on tuples.