Question: I'm really having problems writing a MID formula to extract the due date (always the same length) and Row count (variable length). Could anybody help me please? I'm getting a little lost with nested formulas.

Project in Batch 100 of 120 for A2B\_1414696641872. Due date: **2014-11-03**. Word count: 1976. Row count: **345**.

Strings in column A, column B should contain 2014-11-03 and column C should contain 345

Project in Batch 10 of 12 for A2B\_141469664. Due date: **2014-11-03**. Word count: 19. Row count: **3**.

Strings in column A, column B should contain 2014-11-03 and column C should contain 19

--

I currently have the following for extracting the due date (it works):

```
=MID(LEFT(B1,FIND(". Word count",B1)-1),FIND("Due date:",B1)+10,LEN(B1))

```

Answer: 
Starting in `Python 3.8`, and the introduction of [assignment expressions (PEP 572)](https://www.python.org/dev/peps/pep-0572/) (`:=` operator), it's possible to use a local variable within a list comprehension in order to avoid calling the same function twice.

In our case, we can name the evaluation of `map_to_obj(v)` as a variable `o` while using the result of the expression to filter the list; and thus use `o` as the mapped value:

```
[o for v in [v1, v2, v3, v4] if (o := map_to_obj(v))]

```
List comprehensions are fine for the simple cases, but sometimes a plain old `for` loop is the simplest solution:

```
other_list = []
for v in v_list:
    obj = map_to_obj(v)
    if obj:
        other_list.append(obj)

```

Now if you really want a list comp and dont want to build an tmp list, you can use the iterator versions of `filter` and `map`:

```
import itertools as it
result = list(it.ifilter(None, it.imap(map_to_obj, v_list)))

```

or more simply :

```
import itertools as it
result = filter(None, it.imap(map_to_obj, v_list)))

```

The iterator versions don't build a temporary list, they use lazy evaluation.