0% found this document useful (0 votes)
42 views2 pages

Updated New Task Recursion Lab

The document describes a task to write a recursive function called flattenList that takes a nested Python list and an empty list as parameters. The function should convert the nested list into a new flat list sequentially without using any loops. It provides an example nested input list and expected flat output list. It also suggests an ungraded extension of the task to singly linked lists instead of built-in lists.

Uploaded by

MD RADWAN AHAMED
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views2 pages

Updated New Task Recursion Lab

The document describes a task to write a recursive function called flattenList that takes a nested Python list and an empty list as parameters. The function should convert the nested list into a new flat list sequentially without using any loops. It provides an example nested input list and expected flat output list. It also suggests an ungraded extension of the task to singly linked lists instead of built-in lists.

Uploaded by

MD RADWAN AHAMED
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Task 1:

Complete the recursive function flattenList which will take a nested python list and an empty list
as parameters. The function should convert the nested list into a new flat list sequentially. Check
the input-output to understand the sequence pattern.

def flattenList(given_list, output_list):


# To Do

given_list = [1, [2, [3, [4], 5], 6], 7, 8, [9, [[10, 11], 12], 13], 14, [15, [16, [17]]]]

output_list = flattenList(given_list, []) # Initial empty list is sent for update

output_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]

Your code must work for any depth of the nested linked list. You can not use any loop in the
function. You can use built-in functions like append, type, etc.

Ungraded Task: Do this now for Singly Linked List Instead of Python’s built-in list.

Hint:
Your node class

class Node:
def __init__(self, next, bottom, val):
self.next = next # for next item
self.bottom = bottom # for nested item check
self.val = val # The integer value.

You might also like