从键盘输入列表的值:< __ main __。ListNode>错误

时间:2017-01-25 23:51:53

标签: python

我正在编写一个python程序来合并两个排序列表。但是,在运行此程序时,在尝试从键盘输入其值时,会产生错误:

<__main__.ListNode object at 0x000002D68AD6FFD0>

该计划是:

class ListNode(object):
    def __init__(self,x):
        self.val = x
        self.next = None

class MergeTwoLists(object):
    def mergeTwoLists(self,l1,l2):
        if not l1 or not l2:
            return l1 or l2
        if l1.val < l2.val:
            l1.next = self.mergeTwoLists(l1.next,l2)
            return l1
        else:
            l2.next = self.mergeTwoLists(l1,l2.next)
            return l2

#input the two integer lists
list1 = []
for i in range(0,6):
    list1.append(input("enter a integer of list1:"))
head = ListNode(list1[0])
p = head
for j in list1[1:]:
    node = ListNode(j)
    p.next = node
    p = p.next
l1 = head

list2 = []
for i in range(0,6):
    list2.append(input("enter an integer of list2:"))
head = ListNode(list2[0])
p = head
for j in list2[1:]:
    node = ListNode(j)
    p.next = node
    p = p.next
l2 = head

list_result = MergeTwoLists().mergeTwoLists(l1,l2)
print("the list result:")
print(list_result)

有人可以帮我解决这个问题吗?

0 个答案:

没有答案