# Class 14 - Worksheet

### Upcoming Schedule

Since we didn't get as far in class as expect, Project 3 is extended to Monday, 29 February. Before submitting Project 3 you must have complete the Orange Belt (either by getting a "Gold star" on Project 2 or completing the promotion requirements from Class 13 notes.

## Nested Lists

```def list_copy(lst):
"""Returns a shallow copy of the input lst."""
if not lst:
return []
else:
return [lst] + list_copy(lst[1:])

def is_list(obj):
"""Returns True iff obj is a list."""
return isinstance(obj, list)
```
```def list_deep_copy(lst):
"""Returns a deep copy of the input list."""
if not lst:
return []
elif is_list(lst):
return [list_deep_copy(lst)] + list_deep_copy(lst[1:])
else:
return [lst] + list_deep_copy(lst[1:])
```

Demonstrate the difference between `list_copy` and `list_deep_copy` with some Python code that shows how they behave differently.

```def list_deep_map(fn, lst):
"""
Returns a new list with the same structure as lst, but with each element
replaced by the result of applying fn to that element.
"""
if not lst:
return []
elif is_list(lst):
# finish this code
#
else:
#
#
```
```def list_accumulate(fn, lst, start):

```
```def list_sum(lst):
def
#
return list_accumulate(_______________________, lst, ____)
```
```def list_length(lst):
def
#
return list_accumulate(_______________________, lst, ____)
```
```def list_and(lst):
```
```def list_or(lst):
```
```def list_biggest(lst):
```
```def list_deep_accumulate(lst, fn, base):
```