Note that there are some explanatory texts on larger screens.

plurals
  1. POError in Python Code Creating/Implementing Dictionary
    primarykey
    data
    text
    <p>Here's 2 programs, one to create a dictionary, and the other to implement it, the first one being:-</p> <pre><code> class dictionary: def _init_(self, pword=[]): self.word = pword def addWord(self, nword): l = len(self.word) bp = -1 for num in range(0,l): if self.word[num][0]==nword: return if self.word[num][0]&gt;nword: bp = num break nl = [nword] self.word.append([]) if bp&gt;=0: for num in range(l-1,bp+1,-1): self.word[num] = self.word[num-1] else: bp+=1 (self.word).insert(bp,nl) def addKey(self, nword,key): l = len(self.word) for num in self.word: if num[0]==nword: if num.count(key)==0: num.append(key) return print("'"+nword+"' was not found in the present dictionary\n") def display(self): if len(self.word)==0: print("Dictionary is currently Empty\n") return for num in self.word: for nw in num: print(nw+"\t") print("\n") </code></pre> <p>And the other one is</p> <pre><code>import file def main(): print("Running file") td = file.dictionary() td.addWord("A") td.addWord("B") td.addWord("C") print("Words added") td.addKey("A",1) td.addKey("A",2) td.addKey("B",3) td.addKey("C",1) td.addKey("C",3) print("Keys added") td.display() main() </code></pre> <p>Both the programs compile without a problem But when i run the second one, i get the following error</p> <pre><code>Running file Traceback (most recent call last): File "E:\Documents\Information Retrieval\ptrial.py", line 17, in &lt;module&gt; main() File "E:\Documents\Information Retrieval\ptrial.py", line 5, in main td.addWord("A") File "E:\Documents\Information Retrieval\file.py", line 6, in addWord l = len(self.word) AttributeError: 'dictionary' object has no attribute 'word'** </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload