How to index a list using a variable?
Using the below example, how can a
and b
be used to return the equivalent of a[1]
?
>>> a = range(5)
>>> b = [1]
>>> a[1]
1
>>> a(b)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-46-ec02cd35061d> in <module>()
5 a[1]
6
----> 7 a(b)
TypeError: 'range' object is not callable
>>> (a)b
File "<ipython-input-51-0a1106519cc7>", line 1
(a)b
^
SyntaxError: invalid syntax