As others said in their answers, you will need to generate different objects in order for the comparison to make sense.
So, compare some approaches.
tuple
l = [(i, i) for i in range(10000000)]
class Person
class Person: def __init__(self, first, last): self.first = first self.last = last l = [Person(i, i) for i in range(10000000)]
namedtuple ( tuple + __slots__ )
from collections import namedtuple Person = namedtuple('Person', 'first last') l = [Person(i, i) for i in range(10000000)]
namedtuple is basically a class that extends tuple and uses __slots__ for all named fields, but it adds getters and some other helper methods (you can see the exact code generated if called with verbose=True ).
class Person + __slots__
class Person: __slots__ = ['first', 'last'] def __init__(self, first, last): self.first = first self.last = last l = [Person(i, i) for i in range(10000000)]
This is a shortened version of namedtuple above. A clear winner, even better than pure tuples.
source share