Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Functional Python The Lambda Lambada Reduce

Ross Coe
Ross Coe
5,061 Points

Can you explain how an empty list can be passed in long_total and that's not seen as None?

these steps/checks in long_total are a little confusing...

if a is not None and books and books is not None and b is None:

  • you need the check 'and books' otherwise the long_total borks when b = books.pop(0) - IndexError: pop from empty list

and later if a is not None and b is None and not books or books is None:

  • surely if books is None - there are no books..?
def long_total(a=None, b=None, books=None):
    if a is None and b is None and books is None:
        return None
    if a is None and b is None and books is not None:
        a = books.pop(0) #car
        b = books.pop(0) #car(cdr)
        return long_total(a, b, books)
    if a is not None and books and books is not None and b is None: #need to check books otherwise error trying to pop books(0)
        b = books.pop(0) # is you've a returned value
        return long_total(a, b, books)
    if a is not None and b is not None and books is not None:
        return long_total(a+b, None, books) # if you have a product return without b to step above
    if a is not None and b is not None and not books:
        return long_total(a+b, None, None)
    if a is not None and b is None and not books or books is None:
        return a #ultimate answer/returned value

'''
nakalkucing
nakalkucing
12,964 Points

I was wondering why too. Would you mind answering Craig Dennis?

1 Answer

While both are "falsy", an empty list is not equal to None. After all, and empty list is something.