Relatively new to Python.
I'm trying to practice linked list but I'm stuck with an error and couldn't figure out what the issue is.
The error:
self.assertEqual(l.size(), 1)
TypeError: 'int' object is not callable
The code:
from node import Node
class List:
def __init__(self):
self.head = None
self.size = 0
def add(self, item):
temp = Node(item)
temp.setNext(self.head) # ERROR ON THIS LINE
self.head = temp
size += 1
def size(self):
return self.size
...
Node:
class Node:
def __init__(self, data):
self.data = data
self.next = None
....
Test:
import unittest
import unorderedlist
class TestUnorderedList(unittest.TestCase):
def test_add(self):
l = unorderedlist.List()
l.add(8)
self.assertEqual(l.size(), 1)
if __name__ == '__main__':
unittest.main()
It's funny because if I rename the size() to len and call it like l.len() it works fine. Anyone have a clue?
self._sizefor the data; that way you're not stomping on the method.self.sizea method or data?