List functions | Sololearn: Learn to code for FREE!

+1

List functions

You’re analyzing a data set and need to remove the outliers (the smallest and largest values. The data is stored in a list). Complete the code to remove the smallest and largest elements from the list and output the sum of the remaining numbers.

4/11/2021 4:49:06 PM

Veena Tirmal

24 Answers

New Answer

+5

print(sum(sorted(li)[1:-1])) # Hope this helps

+11

Veena Tirmal Hint:- 1 - remove min value using min function 2 - remove max value using max function 3 - get sum using sum function. You can remove min and max value using remove function.

+9

Veena Tirmal at me it works just fine https://code.sololearn.com/ca2P3aNwkkdD/?ref=app or is this out of a course-exercise? then you should give ALL information like chapter, boundary conditions and not only vague information

+9

🅰🅹 (Challenge Accepted) Msimbuzeey🇹🇿☯🔥 Jan Markus Thanks guys, atlast this worked data = [7, 5, 6.9, 1, 8, 42, 33, 128, 1024, 2, 8, 11, 0.4, 1024, 66, 809, 11, 8.9, 1.1, 3.42, 9, 100, 444, 78] #your code goes here data.remove(max(data)) data.remove(min(data)) print(sum(data))

+5

Welcome! For better help for you please, show us your code attempt! and specify the programming language

+3

Veena Tirmal there's only one thing, the "max" and "min" are functions of a list not its methods Thus, they can't be used alone. you have to specify the lists to be evaluated, i.e max(list_name)... in your case, max(data)

+3

data = [7, 5, 6.9, 1, 8, 42, 33, 128, 1024, 2, 8, 11, 0.4, 1024, 66, 809, 11, 8.9, 1.1, 3.42, 9, 100, 444, 78] ma = max(data) mi = min(data) data1 = [i for i in data if i not in [ma, mi]] print(data1)

+2

Veena Tirmal Show your code.

+1

I tried that, not able to. Invalid syntax 🅰🅹 (Challenge Accepted)

+1

Preferably by using python, try: nums_list=[1,2,3,4,5,6] sum=0 #removing the items with highest and lowest values in the list nums_list.remove(max(nums)) nums_list.remove(min(nums)) #adding the remaining items for a in nums_list: sum+=a print(sum) The list is just an example. Feel free to correct me anyone, in case of an error

+1

L=[1,2,3,4,5,6,7,8,9] mx=mn=L[0] s=0 for i in L:     if i>mx:         mx=i     if i<mn:         mn=i L.remove(mx) L.remove(mn) for j in L:     s+=j print("largest value=",mx) print("Smaller value=",mn) print("Sum of remaining values=",s)

+1

0

data = [7, 5, 6.9, 1, 8, 42, 33, 128, 1024, 2, 8, 11, 0.4, 1024, 66, 809, 11, 8.9, 1.1, 3.42, 9, 100, 444, 78] data.remove(max) data.remove(min) Print(data) 🅰🅹 (Challenge Accepted)

0

Msimbuzeey🇹🇿☯🔥 I tried your method it isn't working

0

Jan Markus not working

0

Check it out https://www.programiz.com/python-programming/methods/list

0

https://code.sololearn.com/c07bIKr6PqAg/?ref=app

0

data =[7,5,6,9,1,8,42,33,128,1024,2,8,11,0.4,1024,66,809,11,8.9,1.1,3.42,9,100,444,78] data.remove(max(data)) data.remove(min(data)) Print(sum(data))

0

you can also plot scatter graphs with seaborne and matplotlib library 🤓

-1