Repository: sympy/sympy

Issue:
Cannot substitute IndexedBase for a list
```py
>>> d = IndexedBase('d')
>>> d[0].subs(d, range(5))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "./sympy/core/basic.py", line 915, in subs
    rv = rv._subs(old, new, **kwargs)
  File "./sympy/core/basic.py", line 1029, in _subs
    rv = fallback(self, old, new)
  File "./sympy/core/basic.py", line 1006, in fallback
    rv = self.func(*args)
  File "./sympy/tensor/indexed.py", line 157, in __new__
    return base[args]
  File "./sympy/sets/fancysets.py", line 923, in __getitem__
    rv = (self.stop if i < 0 else self.start) + i*self.step
TypeError: unorderable types: list() < int()
```

Ideally this would work. 

Discussion:

Patch:
diff --git a/sympy/tensor/indexed.py b/sympy/tensor/indexed.py
index 3e0c2dfbad..b9bcc5e040 100644
--- a/sympy/tensor/indexed.py
+++ b/sympy/tensor/indexed.py
@@ -154,7 +154,10 @@ def __new__(cls, base, *args, **kw_args):
                 Indexed expects string, Symbol, or IndexedBase as base."""))
         args = list(map(sympify, args))
         if isinstance(base, (NDimArray, collections.Iterable, Tuple, MatrixBase)) and all([i.is_number for i in args]):
-            return base[args]
+            if len(args) == 1:
+                return base[args[0]]
+            else:
+                return base[args]
 
         return Expr.__new__(cls, base, *args, **kw_args)
 
@@ -365,10 +368,16 @@ class IndexedBase(Expr, NotIterable):
     is_Atom = True
 
     def __new__(cls, label, shape=None, **kw_args):
+        from sympy import MatrixBase, NDimArray
+
         if isinstance(label, string_types):
             label = Symbol(label)
         elif isinstance(label, Symbol):
             pass
+        elif isinstance(label, (MatrixBase, NDimArray)):
+            return label
+        elif isinstance(label, collections.Iterable):
+            return _sympify(label)
         else:
             label = _sympify(label)
 


Test patch:
diff --git a/sympy/tensor/tests/test_indexed.py b/sympy/tensor/tests/test_indexed.py
index 6280560886..78716a3c64 100644
--- a/sympy/tensor/tests/test_indexed.py
+++ b/sympy/tensor/tests/test_indexed.py
@@ -5,7 +5,7 @@
 
 # import test:
 from sympy import IndexedBase, Idx, Indexed, S, sin, cos, Sum, Piecewise, And, Order, LessThan, StrictGreaterThan, \
-    GreaterThan, StrictLessThan
+    GreaterThan, StrictLessThan, Range, Array
 
 
 def test_Idx_construction():
@@ -353,3 +353,12 @@ def test_indexed_is_constant():
     assert not A[1+2*i, k].is_constant(i)
     assert A[1+2*i, k].is_constant(j)
     assert not A[1+2*i, k].is_constant(k)
+
+
+def test_issue_12533():
+    d = IndexedBase('d')
+    assert IndexedBase(range(5)) == Range(0, 5, 1)
+    assert d[0].subs(Symbol("d"), range(5)) == 0
+    assert d[0].subs(d, range(5)) == 0
+    assert d[1].subs(d, range(5)) == 1
+    assert Indexed(Range(5), 2) == 2