python - __repr__ with 2 lists with multiple items in the List -


hopefully quick answer! direction of appreciated. trying prepare final exam.

this how calling class:

    >>> q = priorityqueue()     >>> q.insert("text",10)     >>> q.insert("hello", 18)     >>> q     text 10, hello 18 

so have class like:

    class priorityqueue():            def __init__(self):               self.items = []               self.priorities = []             def insert(self, x, p):               self.items.append(x)               self.priorities.append(p)             #this dont understand how return how should.            def __repr__(self):                new = []                x in range(len(self.items)):                    new.append(str(self.items[x])+ " " +str(self.priorities[x]))                return [str(x) x in new] 

this give me error like:

      typeerror: __repr__ returned non-string (type list) 

thanks stack!

the __repr__ function must return string, you're returning list. maybe want change return line return '\n'.join(new).


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

How can I fetch data from a web server in an android application? -

jquery - How can I dynamically add a browser tab? -