Issue #25663: Make rlcompleter avoid duplicate global names
diff --git a/Lib/rlcompleter.py b/Lib/rlcompleter.py
index 73f8d80..7f61c67 100644
--- a/Lib/rlcompleter.py
+++ b/Lib/rlcompleter.py
@@ -102,13 +102,16 @@
         """
         import keyword
         matches = []
+        seen = {"__builtins__"}
         n = len(text)
         for word in keyword.kwlist:
             if word[:n] == text:
+                seen.add(word)
                 matches.append(word)
-        for nspace in [__builtin__.__dict__, self.namespace]:
+        for nspace in [self.namespace, __builtin__.__dict__]:
             for word, val in nspace.items():
-                if word[:n] == text and word != "__builtins__":
+                if word[:n] == text and word not in seen:
+                    seen.add(word)
                     matches.append(self._callable_postfix(val, word))
         return matches