NameError - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: NameError (/thread-38478.html) |
NameError - nafshar - Oct-18-2022 I am getting a NameError that I do not understand. It appears the function "combo" is defined in the proper place, so "combo not found" is puzzling to me. class Solution(object): def combo(self, l1, l2): cs = [] for i in range(len(l1)): for j in range(len(l2)): cs.append(l1[i] + l2[j]) return cs def letterCombinations(self, digits): s = combo(["a", "b", "c"], ["d", "e", "f"]) return s
RE: NameError - Gribouillis - Oct-18-2022 Instead of combo() , call self.combo() . Also you can just write class Solution: It is implicit that object is a parent class.
RE: NameError - nafshar - Oct-18-2022 (Oct-18-2022, 01:45 PM)Gribouillis Wrote: Instead of Thank you Griboullis. Adding "self" worked, but puzzling why I get this NameError unless there is another "combo" in python, and I was not able to find it. RE: NameError - deanhystad - Oct-18-2022 There is no combo function. Class Solution has an attribute named combo, so you can call Solution.combo, or you can use an instance of Solution to call combo. |