<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def flatten_tree(tree, nested_attr='replies', depth_first=False):
 """Return a flattened version of the passed in tree. :param nested_attr: The attribute name that contains the nested items. Defaults to ``replies`` which is suitable for comments. :param depth_first: When true, add to the list in a depth-first manner rather than the default breadth-first manner. """

    stack = deque(tree)
    extend = stack.extend if depth_first else stack.extendleft
    retval = []
    while stack:
        item = stack.popleft()
        nested = getattr(item, nested_attr, None)
        if nested:
            extend(nested)
        retval.append(item)
    return retval