Diego
Diego

Reputation: 36166

Sorting error on Jupyter

the following code works perfectly fine on my interpreter

a = [5, 1, 4, 3]
b = sorted(a)

why does it give me this error when I run it from Jupiter:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-71-4a5766271a85> in <module>()
----> 1 b = sorted(a)

TypeError: 'list' object is not callable

Version:

Server Information:
You are using IPython notebook.

The version of the notebook server is 3.2.0-8b0eef4 and is running on:
Python 2.7.10 |Anaconda 2.3.0 (64-bit)| (default, May 28 2015, 16:44:52) [MSC v.1500 64 bit (AMD64)]

Current Kernel Information:
Python 2.7.10 |Anaconda 2.3.0 (64-bit)| (default, May 28 2015, 16:44:52) [MSC v.1500 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.

IPython 3.2.0 -- An enhanced Interactive Python.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
%guiref   -> A brief reference about the graphical user interface.

Upvotes: 3

Views: 974

Answers (1)

falsetru
falsetru

Reputation: 369394

Make sure that the name sorted is not overwritten.

>>> sorted([5,4,3,2,1])
[1, 2, 3, 4, 5]
>>> sorted = []  # <--- overwritten; shadows builtin `sorted` function.
>>> sorted([5,4,3,2,1])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'list' object is not callable

Upvotes: 1

Related Questions