Предположим, у меня есть класс Python
Код: Выделить всё
class myClass():
def __init__(self, neighbor):
self.neighbor = neighbor
Код: Выделить всё
a.neighbor = b
b.neighbor = c
etc.
Конкретно (и наивно) мне нужна функция, которая возвращает
Код: Выделить всё
newList = [a0,b0,c0,d0,...]Код: Выделить всё
a0.neighbor = b0
b0.neighbor = c0
etc.
Код: Выделить всё
def myFunction(myList):
myDict = {}
newList = []
for item in myList:
(create a myClass object called item0)
newList = newList.append(item0)
myDict{item} = item0
# populate the neighbor data for each new item
for item in myList
myDict{item}.neighbor = myDict{item.neighbor}
return newList
Подробнее здесь: https://stackoverflow.com/questions/788 ... -in-a-list