diff --git a/Lib/sre_compile.py b/Lib/sre_compile.py
index b6689fa..0063845 100644
--- a/Lib/sre_compile.py
+++ b/Lib/sre_compile.py
@@ -271,7 +271,7 @@ def _optimize_charset(charset, fixup, fixes, isunicode):
                     else:
                         charmap[av] = 1
                 elif op is RANGE:
-                    r = range(av[0], av[1]+1)
+                    r = xrange(av[0], av[1]+1)
                     if fixup:
                         r = map(fixup, r)
                     if fixup and fixes:
@@ -374,7 +374,7 @@ def _optimize_charset(charset, fixup, fixes, isunicode):
     mapping = bytearray(256)
     block = 0
     data = bytearray()
-    for i in range(0, 65536, 256):
+    for i in xrange(0, 65536, 256):
         chunk = charmap[i: i + 256]
         if chunk in comps:
             mapping[i // 256] = comps[chunk]
-- 
1.8.3.1

