Q:

Python 'int' object is not iterable

I'm in the process of writing one of my first programs and receiving an error when testing it against another program. Below is the snippet of code at the beginning of my program that's first throwing the issue:
def stats(list_doc):

    #Minimum
    min_val = min(list_doc)
    int(min_val)

    #Maximum
    max_val = max(list_doc)
    int(max_val)

    #Mean
    total = sum(list_doc)
    length = len(list_doc)
    for nums in [list_doc]:
        mean_val = total / length
        float(mean_val)

    #Median
    sorted(list_doc)
    med_val = sorted(lst)
    lstLen = len(lst)
    index = (lstLen - 1) // 2

    if (lstLen % 2):
        return med_val[index]
    else:
        return (med_val[index] + med_val[index + 1])/2.0

    return min_val, max_val, mean_val, med_val

And this is the code I'm running it against to actually perform the function against a list of numbers.
    list_doc = list(range(51)) # from 0 to 50. an odd number of elements.
    min_val, max_val, mean_val, med_val = stats(list_doc)
    print("Minimum = {0} is of type {1}.".format(min_val, type(min_val)))
    print("Maximum = {0} is of type {1}.".format(max_val, type(max_val)))
    print("Mean = {0:.1f} is of type {1}.".format(mean_val, type(mean_val)))
    print("Median = {0:.1f} is of type {1}.".format(med_val, type(med_val)))

I receive a TypeError: 'int' object is not iterable. Error text is below:
    TypeError                                 Traceback (most recent call last)
    <ipython-input-25-6a4f116bc5b5> in <module>()
      1 list_doc = list(range(51)) # from 0 to 50. an odd number of elements.
----> 2 min_val, max_val, mean_val, med_val = stats(list_doc)
      3 print("Minimum = {0} is of type {1}.".format(min_val, type(min_val)))
      4 print("Maximum = {0} is of type {1}.".format(max_val, type(max_val)))
      5 print("Mean = {0:.1f} is of type {1}.".format(mean_val, type(mean_val)))

    TypeError: 'int' object is not iterable

I thought that lists were already iterable, but I'm not quite sure what direction to go in from here.

A:

Observe the return value of stats:
In [7]: stats(list_doc)
Out[7]: 0

Now, look at the next statement:
min_val, max_val, mean_val, med_val = stats(list_doc)

This generates an error because you are asking for four values and supplying only one.
If you intend that stats should return four values, then it needs to be modified.
Suggested Code for stats Function
Consider:
def stats(x):
     return min(x), max(x), sum(x)/len(x), sorted(x)[len(x)//2]

Discussion of Code in Revised Question
Consider:
def stats(list_doc):

    #Minimum
    min_val = min(list_doc)
    int(min_val)
    return min_val

    #Maximum
    max_val = max(list_doc)
    int(max_val)
    return max_val

    #Mean
    total = sum(list_doc)
    length = len(list_doc)
    for nums in [list_doc]:
        mean_val = total / length
        float(mean_val)
        return mean_val

    #Median
    sorted(list_doc)
    med_val = sorted(lst)
    lstLen = len(lst)
    index = (lstLen - 1) // 2

    if (lstLen % 2):
        return med_val[index]
    else:
        return (med_val[index] + med_val[index + 1])/2.0

    return min_val, max_val, mean_val, med_val

When a python function encounters a return statement, it returns.  Thus, after computing the minimum, the following statement is executed:
    return min_val

With that statement, the function execution stops.  None of the statements which follow it are executed.
Separately, consider this statement:
int(min_val)

This function takes the value of min_val and returns it as  an integer.  The return of value of the function is not assigned to anything.  Therefore, it is ignored.  The value of min_val is unchanged.  Maybe, the intent is:
min_val = int(min_val)

Also, consider the line:
sorted(list_doc)

This line returns a sorted list but the return value is ignored.  list_doc remains unchanged.  If you want to change list_doc in place, use:
list_doc.sort()

A:

Your stats() function isn't return everything you want. You probably meant to do something like 
def stats(list_doc):

    #Minimum
    min_val = min(list_doc)
    max_val = ...
    mean_val = ...
    med_val = ...
    return min_val, max_val, mean_val, med_val

