+ 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
Veena Tirmal - avatar
32 ответов
+ 9
print(sum(sorted(li)[1:-1])) # Hope this helps
13th Apr 2021, 1:32 PM
Calvin Thomas
Calvin Thomas - avatar
+ 13
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
A͢J - avatar
+ 12
🅰🅹 (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
Veena Tirmal - avatar
+ 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
Yaroslav Vernigora - avatar
+ 3
Veena Tirmal Show your code.
11th Apr 2021, 5:52 PM
A͢J
A͢J - avatar
+ 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🇹🇿☯🔥
Msimbuzeey🇹🇿☯🔥 - avatar
+ 2
Demissew Getachew This is 1 year old question and also user is no more active. So please try to give answer on latest questions.
13th Feb 2023, 9:40 AM
A͢J
A͢J - avatar
+ 1
I tried that, not able to. Invalid syntax 🅰🅹 (Challenge Accepted)
11th Apr 2021, 5:43 PM
Veena Tirmal
Veena Tirmal - avatar
+ 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🇹🇿☯🔥
Msimbuzeey🇹🇿☯🔥 - avatar
+ 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
Aman Jain - avatar
+ 1
3rd May 2021, 11:01 AM
hareesh menikonda
hareesh menikonda - avatar
+ 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
A͢J - avatar
+ 1
girraj yadav Jo bhi puchna hai yahan pucho no WhatsApp no Instagram
9th Jan 2022, 7:55 AM
A͢J
A͢J - avatar
+ 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
José Catela
José Catela - avatar
+ 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
Darshan Agravat
Darshan Agravat - avatar
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
Veena Tirmal - avatar
0
Msimbuzeey🇹🇿☯🔥 I tried your method it isn't working
11th Apr 2021, 6:20 PM
Veena Tirmal
Veena Tirmal - avatar
0
Jan Markus not working
12th Apr 2021, 1:05 AM
Veena Tirmal
Veena Tirmal - avatar
0
https://code.sololearn.com/c07bIKr6PqAg/?ref=app
12th Apr 2021, 7:25 PM
Oladimeji Elijah
Oladimeji Elijah - avatar