Skip to content

Instantly share code, notes, and snippets.

@andymccurdy
Created August 9, 2016 01:15
Show Gist options
  • Save andymccurdy/ec110381a2dab1f689e995c198030ae2 to your computer and use it in GitHub Desktop.
Save andymccurdy/ec110381a2dab1f689e995c198030ae2 to your computer and use it in GitHub Desktop.
def purify(numbers):
return [i for i in numbers if i % 2 == 0]
@andymccurdy
Copy link
Author

def remove_duplicates(numbers):
    new_list = []
    for x in numbers:
        if x not in new_list:
            new_list.append(x)
    return new_list

@jbwhite85
Copy link

def median(x):
    med_list = []
    for i in x:
        if x not in med_list:
            med_list.append(x)
    med_list = sorted(med_list)

Essentially, I need to put the numbers that come through 'x' into a list. Next I need to sort said list...which I believe i've done both. Now what I don't know how to do is take the middle number, or if it's an even value of numbers, taking the middle two numbers, dividing them, and outputting the median.

@jbwhite85
Copy link

def median(x):
    med_list = sorted(x)
    if len(med_list) % 2 == 1:
        return the middle index
    else:
        figure out how to divide the middle indexes and return it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment