Question: I have a list like this:

```
dates = [
    datetime.date(2014, 11, 24),
    datetime.date(2014, 11, 25),
    datetime.date(2014, 11, 26),
    # datetime.date(2014, 11, 27), # This one is missing
    datetime.date(2014, 11, 28),
    datetime.date(2014, 11, 29),
    datetime.date(2014, 11, 30),
    datetime.date(2014, 12, 1)]

```

I'm trying to find the missing dates between the start and end date, with this expr:

```
date_set = {dates[0] + timedelta(x) for x in range((dates[-1] - dates[0]).days)}

```

Strangely enough, it throws an error - it can't access the `dates` variable. But this expression runs fine:

```
date_set = {date(2015,2,11) + timedelta(x) for x in range((dates[-1] - dates[0]).days)}

```

I wrote an expression that does what I wanted:

```
def find_missing_dates(dates: list[date]) -> list[date]:
    """Find the missing dates in a list of dates (that should already be sorted)."""
    date_set = {(first_date + timedelta(x)) for first_date, x in zip([dates[0]] * len(dates), range((dates[-1] - dates[0]).days))}
    missing = sorted(date_set - set(dates))

    return missing

```

It's an ugly expression and forced me to fill a second list with the same variable. Does anyone have a cleaner expression?

Answer: 
return will cause a function to exit... if you use yield you can make it a generator

```
def list_num_checker(num_list):
    for x in num_list:
        if x%2==0:
            yield x # yield makes this a generator instead
        # else: # you don need the else
        #    continue

for evennum in list_num_checker([1,2,3,4,5,6,7,8]):
    print(evennum)

```

you could also make a list comprehension

```
print([x for x in num_list if x%2 == 0])

```

or you could use the builtin filter function

```
def is_even(num):
    return num % 2 == 0

list(filter(is_even,num_list)) # its a generator so you need to call list on it

```
I think you can use `yield` instead of `return` since `return` will break the `for` loop and immediately returns the give value

```
def list_num_checker(num_list):
    for x in num_list:
        if x%2==0:
            yield x
        else:
            continue

divisible2 = list(list_num_checker([1,2,3,4,5,6]))

```

Some possible alternative approaches would be to use list comprehension or `filter`

```
def list_num_checker(num_list):
    return [x for x in num_list if x % 2 == 0]

```

```
def list_num_checker(num_list):
    return filter(lambda x: x % 2 == 0, num_list)

```