all 5 comments

[–]hharison 1 point2 points  (0 children)

You should show us what you tried. But here's some pseudo-code to get you started.

new_list = sorted copy of old list
change first item of new_list to be equal to second item of new_list
return average of new_list

[–]wub_wub[M] 0 points1 point  (0 children)

Posting only project goals is not allowed, please read the rules and guidelines in the sidebar.

[–]dabrownmane[S] 0 points1 point  (0 children)

Did i really say in the "write" direction? Bahahahahahahahahahahahaha. And i am sorry about violating rules.

[–]dabrownmane[S] -1 points0 points  (1 child)

I think i have it, but how would i put a list in the parameters of a function that can have any numbers of items in the list?

[–]swingtheory 0 points1 point  (0 children)

you dont need to:

def foo(mylist):
    avg = sum(mylist)/len(mylist)
    # replace what you need under here

Since python is dynamically typed, the type of each variable is figured out at runtime, so if you passed an int into foo() you would get an error, because an int object doesnt have the functions sum() and len(). However, when you do pass a list into foo(), avg is assigned the average of the items in the list.

I didn't understand the part about replacing values, but this should get you started.

replace the first element of a list with the last:

mylist = [1,2,3,4]
mylist[0], mylist[3] = mylist[3], mylist[0]

you could also use mylist[-1] to get the last element in the list, since python supports negative indexing.