我試圖cbind或unnest或as.data.table一個部分嵌套列表。 id <- c(1,2)
A <- c("A1","A2","A3")
B <- c("B1")
AB <- list(A=A,B=B)
ABAB <- list(AB,AB)
nested_list <- list(id=id,ABAB=ABAB)
id爲length相同(在此情況2)ABAB。我不知道如
因此,x是我在嵌套列表t中查找的值。我理解整個代碼和列表理解會發生什麼,我不明白的是[5]成爲路徑的哪一點,然後[3,5]成爲路徑,最後返回[1,3,5]以顯示價值的最終路徑。 def findPath(t, x):
if t[0] == x:
return [t[0]]
for path in [findPath(branch, x) for branch in