我在代码下面运行以从链接列表中删除重复项.但我的代码只删除重复项之前打印链接列表.一旦调用removeDup方法,它就不会打印任何内容.以下是我的代码.请告诉我我错过了什么.
class Node:
def __init__(self, data):
self.data = data
self.next = None
class LinkedList:
def __init__(self):
self.head = None
def insert(self, data):
node = Node(data)
node.next=self.head
self.head = node
def printl(self):
current = self.head
while current:
print current.data
current= current.next
def removeDups(self):
current = self.head
while current is not None:
second = current.next
while second:
if second.data == current.data:
current.next = second.next.next
second = second.next
current = current.next
# l.printl()
l= LinkedList()
l.insert(15)
l.insert(14)
l.insert(16)
l.insert(15)
l.insert(15)
l.insert(14)
l.insert(18)
l.insert(159) …Run Code Online (Sandbox Code Playgroud) 我有一个二维数组,
a= [[ 1 5 9]
[ 5 8 9]
[-9 6 2]]
Run Code Online (Sandbox Code Playgroud)
我想在这个数组中找到第二个最小或最大数字。例如 pad = -9 这是这个数组中的最小值,我想得到最小值 = 1。例如。
if(np.amin(a)== pad):
min = 1
Run Code Online (Sandbox Code Playgroud)
我正在寻找一个返回第二个最小值的行函数。它也应该能够在以下情况下找到答案:
k = [-999. -999. -999. -999. 43. 40. -999. 14. 15.]
Run Code Online (Sandbox Code Playgroud)
在这种情况下,当我们排序时
k = [-999. -999. -999. -999. -999. 14. 15. 40. 43.]
min = 14
Run Code Online (Sandbox Code Playgroud)
更新 1
nodatavalue = -999.0
if(np.amin(k) == nodatavalue):
np.amin(np.array(a)[a != np.amin(a)])
else:
np.amin(k)
Run Code Online (Sandbox Code Playgroud) python-2.7 ×2