Question: I'm making a script to extract html code from .html files in a directory which happen to have non-html code outside the html tags. I wish for the output overwrite the source files

Here is what I have so far but I'm having trouble getting it work.

```
#!/bin/bash

for f in `ls .`; do
if [[ $f =~ \.html$ ]] 
then
    cat $f | tr "\n" "|" | grep -o '<html>.*</html>' | sed 's/|/\n/g' > $f
fi
done

```

Answer: 
You can assign to a [slice](https://stackoverflow.com/q/509211/2555451) of list `a` like so:

```
>>> a = [1, 2, 3, 7, 8]
>>> b = [4, 5, 6]
>>> a[3:3] = b
>>> a
[1, 2, 3, 4, 5, 6, 7, 8]
>>>

```

The `[3:3]` may look weird, but it is necessary to have the items in list `b` be inserted into list `a` correctly. Otherwise, if we were to assign to an index of `a`, list `b` itself would be inserted:

```
>>> a = [1, 2, 3, 7, 8]
>>> b = [4, 5, 6]
>>> a[3] = b
>>> a
[1, 2, 3, [4, 5, 6], 8]
>>>

```

---

I tried to find a docs link which explicitly mentions this behavior, but was unsuccessful (please feel free to add one if you can find it). So, I'll just say that doing `a[3:3] = b` tells Python to take the items in list `b` and place them in the section of list `a` represented by `[3:3]`. Moreover, Python will extend list `a` as necessary to accommodate this operation.

In short, this is just yet another awesome feature of Python. :)
Try using the sort method as follows:

```
>>> a = [1,2,3,7,8]
>>> b = [4,5,6]
>>> a = sorted(a+b)
>>> a
[1, 2, 3, 4, 5, 6, 7, 8]

```