The performance searching in a list or a tuple is both the same and both bad. Better performance has searching inside a string or in indexed types like set and dict whereas instantiating them is time consuming.
Using list may lead to unexpected side effects because they are mutable objects whereas tuples are immutable. I remember bugs with lists as parameters to methods or setting a view to lists inside family file content and change them instead of copy its values. That's the reason why I prefer tuples when the content never has to be changed.
For the given example there is no difference.
Greetings xqt
----- Original Nachricht ---- Von: Merlijn van Deen valhallasw@arctus.nl An: Pywikipedia discussion list pywikipedia-l@lists.wikimedia.org Datum: 07.06.2014 00:13 Betreff: Re: [Pywikipedia-l] lists vs tuples
On 6 June 2014 23:49, Ricordisamoa ricordisamoa@openmailbox.org wrote:
Should we always use tuples when instantiating them only once? E.g. *if* abc *in* ('e', 'f'): instead of *if* abc *in* ['e', 'f']:
Performance-wise, I don't think it matters much; after all, most time is spent inside the loop, not in instantiating a list or tuple. Conceptually, a list often makes more sense (a list would be different items of the same type, while a tuple represents different properties of the same item).
Merlijn
Pywikipedia-l mailing list Pywikipedia-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikipedia-l