0

Python's intern function lets you save memory if you have a lot of copies of the same string floating around, by replacing them all with references to a single object.

I have a similar situation, except that instead of strings I'm dealing with longs.

Is there a way to do something similar with longs?

Taymon
  • 24,950
  • 9
  • 62
  • 84
  • 2.7. The docs don't say anything about deprecation, although I'm aware the function was moved to the `sys` module in Python 3. – Taymon May 13 '14 at 09:04
  • AFAIK no. You could simply keep a `dict` and whenever you want to replace a `long` by its unique representation replace it with the value in the `dict`. Note however that you really must have a lot of *very* big `long`s with many repetitions to save significant memory. – Bakuriu May 13 '14 at 09:04

0 Answers0