Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NameError
#1
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
Error:
NameError: global name 'combo' is not defined s = combo(["a", "b", "c"], ["d", "e", "f"]) Line 16 in letterCombinations (Solution.py) ret = Solution().letterCombinations(param_1) Line 39 in _driver (Solution.py) _driver() Line 49 in <module> (Solution.py)
Reply
#2
Instead of combo(), call self.combo(). Also you can just write class Solution: It is implicit that object is a parent class.
Reply
#3
(Oct-18-2022, 01:45 PM)Gribouillis Wrote: Instead of combo(), call self.combo(). Also you can just write class Solution: It is implicit that object is a parent class.

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.
Reply
#4
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  NameError: NameError: global name 'BPLInstruction' is not defined colt 7 4,478 Oct-27-2019, 07:49 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020