'"TypeError: 'set' object is not callable"
I have two iPython notebook installations. One on an AWS Micro Instance, the second using Anaconda on my Macbook (OS X Yosemite). I encountered a difference in the way both of them handle the following code:
my_list = [1, 2, 3, 0, 5, 10, 11, 1, 5]
your_list = [1, 2, 3, 0, 12, 13]
my_set = set(my_list)
your_set = set(your_list)
print my_set
print len(my_set)
print len(my_list)
On iPython-AWS, my output is:
set([0, 1, 2, 3, 5, 10, 11])
7
9
On iPython-Macbook, my output is:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-29-cd060f1b0bde> in <module>()
1 my_list = [1, 2, 3, 0, 5, 10, 11, 1, 5]
2 your_list = [1, 2, 3, 0, 12, 13]
----> 3 my_set = set(my_list)
4 your_set = set(your_list)
5 print my_set
TypeError: 'set' object is not callable
Additionally, these are the installation details, if relevant: 1. iPython on AWS Micro Instance: http://i.stack.imgur.com/qYrq8.png
- iPython Notebook on Macbook - http://i.stack.imgur.com/Q6Id5.png
I cannot seem to find the reason for this difference, although I did come across many threads on Stackoverflow regarding the "TypeError: 'set' object is not callable" issue. I will appreciate any help in understanding why this is so, and if there is anything I can do to ensure my code runs on both installations.
Solution 1:[1]
You can restart the kernel in the top menu. Kernel->Restart
Solution 2:[2]
Simply remove any predefined variable you have assigned, may be intentionally or unintentionally & the error will be vanished.
I have wrongly placed = sign between print statement & brackets like print=(A|B); due to which it was happening.
After clearing print variable it was fine.
Solution 3:[3]
Write:
my_set = set
my_set.update(my_list)
Do not use brackets.
Solution 4:[4]
[FIXED]
TypeError: 'set' object is not callable
As we know set is a 'built-in function'
you just add (del set) before you assign any variable and run the program
P.S : later you can remove it.
Example:
tuple_data = {'A','B',1, 2, 'B','A'}
#del set
var_1 = set(tuple_data)
print(var_1)
type(var_1)
output:
{1, 2, 'B', 'A'}
set
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Xavier Sebastian Vaca Ordoñez |
| Solution 2 | Suresh Maidaragi |
| Solution 3 | ouflak |
| Solution 4 |
