List functions | Sololearn: Learn to code for FREE!

+6

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

29 Answers

New Answer

+5

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

+11

🅰🅹 (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))

+10

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.

+8

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

+3

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

+2

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)

+2

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)

+1

Veena Tirmal Show your code.

+1

girraj yadav Jo bhi puchna hai yahan pucho no WhatsApp no Instagram

0

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

0

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

0

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)

0

0

IMHO, this is not a good way to think about what list() does. True, square brackets [] are used to write a list literal, and are used when you tell a list to represent itself as a string, but ultimately, that's just notation. It's better to think of a Python list as a particular kind of container object with certain properties, eg it's ordered, indexable, iterable, mutable, etc.

0

girraj yadav If you have any problem just ask with a new question. Don't spam in others question. https://www.sololearn.com/discuss/1316935/?ref=app

0

In Python, you can use a list function which creates a collection that can be manipulated for your analysis. This collection of data is called a list object. While all methods are functions in Python, not all functions are methods. https://www.liteblue.life/

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)) total=0.00 i=0 tamanho=len(data) while i < tamanho: total=total+data[i] i=i+1 print(total)

-1

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)

-1

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

-1

Jan Markus not working