【发布时间】:2015-07-22 02:32:11
【问题描述】:
我已经检查了一些想法和原因,下面针对这个问题进行了调查...... "Too many values to unpack" Exception (Stefano Borini 的解释)
但在这里我将列表作为理解列表进行迭代并将结果移动到列表中......!
所以输入的数量读取输出变量的数量,即tempList...
那么,这个过程有什么问题呢?!
def DoProcess(self, myList):
tempList = []
tempList = [[x,y,False] for [x,y] in myList]
return tempList
编辑 1:myList 是一个列表列表,就像 [[x1, y1], [x2, y2], [x3, y3], [x4 y4]]。
class Agent(object):
def __init__(self, point = None):
self.locationX = point.x
self.locationY = point.y
def __iter__(self):
return self
def __next__(self):
return [self.locationX, self.locationY]
def __getItem__(self):
return [self.locationX, self.locationY]
def GenerateAgents(self, numberOfAgents):
agentList = []
while len(agentList) < numberOfAgents:
point = Point.Point()
point.x = random.randint(0, 99)
point.y = random.randint(0, 99)
agent = Agent(point)
agentList.append(agent)
return agentList
def DoProcess(self, myList):
tempList = []
tempList = [[x[0],x[1],False] for x in myList]
return myList
每个Point 有两个属性locationX 和locationY...
【问题讨论】:
-
myList的结构是什么? -
myList 是否包含 2 个元素元组的列表?如果它们每个都有超过 2 个元素,那么你会遇到麻烦。
-
请检查应用的编辑...
-
@Ordenador:那么您的输入实际上并不符合您的规范。你能分享一下
myList到底是什么吗? -
@Ordenador 您应该准确打印列表中的内容,显然您有一个原子对象列表。或者你有一个混合对象的列表。
标签: python