+ 2

# 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.

11th Apr 2021, 4:49 PM
Veena Tirmal
+ 6
print(sum(sorted(li)[1:-1])) # Hope this helps
13th Apr 2021, 1:32 PM
Calvin Thomas
+ 12
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.
11th Apr 2021, 5:27 PM
AÍ¢J
+ 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))
12th Apr 2021, 1:27 AM
Veena Tirmal
+ 5
Welcome! For better help for you please, show us your code attempt! and specify the programming language
11th Apr 2021, 5:09 PM
Yaroslav Vernigora
+ 3
11th Apr 2021, 5:52 PM
AÍ¢J
+ 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)
11th Apr 2021, 6:19 PM
MsimbuzeeyðŸ‡¹ðŸ‡¿â˜¯ðŸ”¥
+ 1
I tried that, not able to. Invalid syntax ðŸ…°ðŸ…¹ (Challenge Accepted)
11th Apr 2021, 5:43 PM
Veena Tirmal
+ 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
11th Apr 2021, 5:52 PM
MsimbuzeeyðŸ‡¹ðŸ‡¿â˜¯ðŸ”¥
+ 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)
20th Apr 2021, 6:41 PM
Aman Jain
+ 1
3rd May 2021, 11:01 AM
hareesh menikonda
+ 1
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.
12th Oct 2021, 12:15 PM
Rogers597
+ 1
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
9th Jan 2022, 6:28 AM
AÍ¢J
+ 1
girraj yadav Jo bhi puchna hai yahan pucho no WhatsApp no Instagram
9th Jan 2022, 7:55 AM
AÍ¢J
+ 1
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/
11th Jan 2022, 10:21 AM
Leone K. Lawrence
+ 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)) data.remove(min(data)) total=0.00 i=0 tamanho=len(data) while i < tamanho: total=total+data[i] i=i+1 print(total)
26th Jan 2022, 9:48 PM
+ 1
// To find Max int max=0; for(int i=0;i<lenth;i++) // lenth = size of list { if(max<list[i]) { max = list[i]; } } // After execution of for loop max have a value who is maximum in the list. // To find Min int min=list[0]; for(int i=0;i<lenth;i++) // lenth = size of list { if(min>=list[i]) { min = list[i]; } } // After execution of for loop min have a value who is minum in the list. // Then just remove max and min using the Remove function. // To find Sum int sum=0; for(int i=0;i<lenth;i++) // lenth = size of list { sum = sum+list[i]; } // After execution of for loop sum have a value of summation of the list.
27th Mar 2022, 7:30 AM
Darsahan Agravat
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)
11th Apr 2021, 6:02 PM
Veena Tirmal
0
MsimbuzeeyðŸ‡¹ðŸ‡¿â˜¯ðŸ”¥ I tried your method it isn't working
11th Apr 2021, 6:20 PM
Veena Tirmal
0
Jan Markus not working
12th Apr 2021, 1:05 AM
Veena Tirmal
12th Apr 2021, 1:42 PM
A J