Here's a Python code for the function:

```
def filter_list(lst, substr):
    filtered_list = []
    for item in lst:
        if substr in item:
            filtered_list.append(item)
    return filtered_list
```

You can call the function by passing the list and the substring as arguments:

```
my_list = ["apple", "orange", "banana", "watermelon", "cherry"]
my_string = "an"

filtered_list = filter_list(my_list, my_string)
print(filtered_list)  # Output: ["banana", "watermelon"]
```
list = ["apple", "orange", "banana", "watermelon", "cherry"]
string = "an"
Scrivi una funzione per filtrare un elenco in base agli elementi che contengono una determinata stringa.