Hi guys, welcome to introduction to DocTesting.

The kata is composed of two parts; in part (1) we write three small functions, and in part (2) we write a few doc tests for those functions.

Lets talk about the functions first...

    The reverse_list function takes a list and returns the reverse of it.
    If given an empty list, simply return an empty list.

The second function...

    The sum_list function takes a list as input and adds up all the values, 
    returning an integer. If the list is empty, return 0.

The third function...

    The head_of_list function simply returns the first item in the list.
    If the list is empty return None.

Each of these functions can be easily written with a single line of code; there are some tests for correctness but no tests for effciency.

Once you have implemented all three of these functions you can move onto phase two, which is writing doc tests. If you haven't written doc tests before then I suggest you check out the following documentation: 
https://docs.python.org/3/library/doctest.html

To complete this kata all you have to do is write **EXACTLY TWO** doc tests for each of the three functions (any more/less than that and you will fail the tests).

Here is an example:

    def double(y):
      """Function returns y * 2
      >>> double(2)
      4
      """
      return y * 2

In the example above we have a function called 'double' and a single doctest. When we run the doctest module Python will check if double(2) equals 4. If it does not, then the doctest module will flag up an error.

Please note that this is intended as a beginners introduction to docstrings, if you try to do something clever (such as writing doc tests to catch exceptions, or tinkering with the 'option flags'), you will probably fail a test or two. This is due to how the tests are written.  

Oh and one last thing, don't try and get too 'cheeky' and try something like:
    
    """
    >>> True
    True
    """

such a solution is (a) not in the spirit of things and (b) I got tests for that! :p

Good Luck!

~~~~~~~~~~~~~~~ Issues & Helpful hints ~~~~~~~~~~~~~~~~~~~~~~~

1) In addition to the 'don't get too clever rule', please try to be precise when making your doctests; [1,2] may fail where [1, 2] may succeed. Likewise, ">>>function(x)" may fail where ">>> function(x)" is likely to suceed *(note the difference is single " " character)*. In short, if you fail a test the first thing to check is that you dont have any unecessary characters/spaces and/or odd formating.

2) As you shall see from the kata discussion testing for None is tricky and lots of people are struggling to get None tests working. So I'm going to quickly show you a way to test for not that will (should) pass the kata:
  
    def is_string(string):
        """
        returns the string if the string is Not empty, otherwise returns None
        >>> is_string("") is None
        True
        """
        return string if string else None

3) If you happen to be struggling to actually complete the three functions in the first place then I would recomend you google *"Python Indexing", "Pythons sum function" and "if/else statements in Python"*.

Difficulty: introductory

Starter code:

def reverse_list(x):
	

Solutions:
def reverse_list(x):
    """Takes an list and returns the reverse of it. 
    If x is empty, return [].
    
    >>> reverse_list([1, 2, 3, 4])
    [4, 3, 2, 1]
    >>> reverse_list([])
    []
    """ 
    
    return x[::-1]

def sum_list(x):
    """Takes a list, and returns the sum of that list.
    If x is empty list, return 0.

    >>> sum_list([1, 2, 3, 4])
    10
    >>> sum_list([])
    0
    """

    return sum(x)

def head_of_list(x):
    """Takes a list, returns the first item in that list.
    If x is empty, return None

    >>> head_of_list([1, 2, 3, 4])
    1
    >>> head_of_list([]) is None
    True
    """ 

    return x[0] if x else None

def reverse_list(lst):
    """Takes an list and returns the reverse of it. 
    If x is empty, return [].
    >>> reverse_list([])
    []
    >>> reverse_list([1, 2, 3])
    [3, 2, 1]
    """ 
    return lst[::-1]

def sum_list(lst):
    """Takes a list, and returns the sum of that list.
    If x is empty list, return 0.
    >>> sum_list([])
    0
    >>> sum_list([1, 2, 3])
    6
    """
    return sum(lst)

def head_of_list(lst):
    """Takes a list, returns the first item in that list.
    If x is empty, return None
    >>> head_of_list([]) is None
    True
    >>> head_of_list([1, 2, 3])
    1
    """
    return lst[0] if lst else None

def reverse_list(x):
    """Takes an list and returns the reverse of it. 
    If x is empty, return [].
    
    >>> reverse_list([1, 2, 3])
    [3, 2, 1]
    
    >>> reverse_list([])
    []
    """ 
    
    return x[::-1]

def sum_list(x):
    """Takes a list, and returns the sum of that list.
    If x is empty list, return 0.

    >>> sum_list([1, 2, 3])
    6

    >>> sum_list([])
    0
    """

    return sum(x)

def head_of_list(x):
    """Takes a list, returns the first item in that list.
    If x is empty, return None

    >>> head_of_list([0, 1])
    0
    
    >>> head_of_list([]) is None
    True
    """ 

    return x[0] if x else None


def reverse_list(x):
    """
    >>> reverse_list([1,2,3])
    [3, 2, 1]
    
    >>> reverse_list([2,3])
    [3, 2]
    """ 
    return x[::-1]

def sum_list(x):
    """
    >>> sum_list([1,2,3])
    6
    
    >>> sum_list([0])
    0
    """
    return sum(x)

def head_of_list(x):
    """
    >>> head_of_list([0])
    0
    
    >>> head_of_list([1,2,3])
    1
    """ 
    return x[0] if x else None

def reverse_list(x):
    """Takes an list and returns the reverse of it. 
    If x is empty, return [].
    
    Your two Doc_tests go here... 
    
     >>> reverse_list([1,2])
     [2, 1]
     >>> reverse_list([])
     []
     """
        
    # Your code goes here...
    return x[::-1]
def sum_list(x):
    """Takes a list, and returns the sum of that list.
    If x is empty list, return 0.

    Your two Doc_tests go here...
    >>> sum_list([])
    0
    >>> sum_list([1,2,3])
    6
    """

    # Your code goes here...
    return 0 if len(x) == 0 else sum(x)
def head_of_list(x):
    """Takes a list, returns the first item in that list.
    If x is empty, return None

    Your two Doc_tests go here...
    >>> head_of_list([1,2,3])
    1
    >>> head_of_list([2,4,5])
    2
    """ 

    # Your code goes here...
    return None if len(x) == 0 else x[0]

def reverse_list(x):
    """Takes an list and returns the reverse of it. 
    If x is empty, return [].
    
    >>> reverse_list([1, 2, 3])
    [3, 2, 1]
    >>> reverse_list([])
    []
    """ 
    return x[::-1] if x else []


def sum_list(x):
    """Takes a list, and returns the sum of that list.
    If x is empty list, return 0.
    >>> sum_list([1, 2, 3])
    6
    >>> sum_list([])
    0
    """

    return sum(x) if x else 0


def head_of_list(x):
    """Takes a list, returns the first item in that list.
    If x is empty, return None

    >>> head_of_list([1, 2])
    1
    >>> head_of_list([]) is None
    True
    """ 

    return x[0] if x else None



def reverse_list(a):
    """Takes an list and returns the reverse of it. 
    If x is empty, return [].
    
    >>> reverse_list([1])
    [1]
    >>> reverse_list([])
    []
    """
    return a[::-1]

def sum_list(a):
    """Takes a list, and returns the sum of that list.
    If x is empty list, return 0.

    >>> sum_list([1])
    1
    >>> sum_list([])
    0
    """
    return sum(a)

def head_of_list(a):
    """Takes a list, returns the first item in that list.
    If x is empty, return None

    >>> head_of_list([1])
    1
    >>> head_of_list([]) is None
    True
    """
    if a:
        return a[0]

def reverse_list(x):
    """Takes an list and returns the reverse of it. 
    If x is empty, return [].
    
    >>> reverse_list([])
    []
    
    >>> reverse_list([1, 2, 3])
    [3, 2, 1]
    """  
    return x[::-1]

def sum_list(x):
    """Takes a list, and returns the sum of that list.
    If x is empty list, return 0.

    >>> sum_list([])
    0
    
    >>> sum_list([1, 2, 3])
    6
    """
    return sum(x)

def head_of_list(x):
    """Takes a list, returns the first item in that list.
    If x is empty, return None
    
    >>> head_of_list([1, 2, 3])
    1
    
    >>> head_of_list([]) is None
    True
    
    
    """ 
    return x[0] if len(x) else None


def reverse_list(x):
    """Takes an list and returns the reverse of it. 
    If x is empty, return [].
    
    >>> reverse_list([])
    []
    >>> reverse_list([5, 4,3, 2, 1])
    [1, 2, 3, 4, 5]
    """ 
    return x[::-1]

def sum_list(x):
    """Takes a list, and returns the sum of that list.
    If x is empty list, return 0.

    >>> sum_list([])
    0
    >>> sum_list([1, 2, 3, 4, 5])
    15
    """
    return sum(x)

def head_of_list(x):
    """Takes a list, returns the first item in that list.
    If x is empty, return None

    >>> head_of_list([]) is None
    True
    >>> head_of_list([1, 2, 3, 4, 5])
    1
    """ 
    return x[0] if x else None


def reverse_list(x):
    """"Takes an list and returns the reverse of it. 
    If x is empty, return [].
    
    Your two Doc_tests go here... 
    >>> reverse_list([])
    []
    >>> reverse_list([2,3,9])
    [9, 3, 2]
    """
    return x[::-1]
def sum_list(x):
    """Takes a list, and returns the sum of that list.
    If x is empty list, return 0.

    Your two Doc_tests go here...
    >>> sum_list([])
    0
    >>> sum_list([2,3,9])
    14
    """
    return sum(x)

def head_of_list(x):
    """Takes a list, returns the first item in that list.
    If x is empty, return None

    Your two Doc_tests go here...
    >>> head_of_list([5,4,9])
    5
    >>> head_of_list([2,3,9])
    2
    """
    if x == []:
        pass
    else:
        return x[0]