py3: why deque doesn't work? - LeetCode Discuss
leetcode.com › problems › n-ary-tree-preorderAttributeError: 'list' object has no attribute 'val', pointing to the: nums.append(node.val) in the while loop. import collections class Solution: def preorder (self, root: 'Node') -> List[int]: if not root: return [] nums = [] nodeStack = collections.deque([root]) while nodeStack: node = nodeStack.popleft() nums.append(node.val) if node.children: nodeStack.appendleft(node.children) return ...