1

I just tested out my system's memory and noticed something:

Python 2:

from sys import getsizeof
x1 = range(50)
x2 = list(range(50))
getsizeof(x1) #472
getsizeof(x2) #568
x1==x2 #True

Python 3:

from sys import getsizeof
x1 = [x for x in range(50)]
x2 = list([x for x in range(50)])
getsizeof(x1) #528
getsizeof(x2) #560
x1==x2 #True

If I nest more list() functions around x2, it is still the same as just one.

Moses Koledoye
  • 77,341
  • 8
  • 133
  • 139
Max Candocia
  • 4,294
  • 35
  • 58

0 Answers0