+ 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.
26 Réponses
+ 9
print(sum(sorted(li)[1:-1]))
# Hope this helps
+ 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.
+ 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))
+ 5
Welcome! For better help for you please, show us your code attempt! and specify the programming language
+ 3
Veena Tirmal
Show your code.
+ 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)
+ 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.
+ 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
+ 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
+ 1
girraj yadav
Jo bhi puchna hai yahan pucho no WhatsApp no Instagram
+ 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)
+ 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.
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
https://code.sololearn.com/c07bIKr6PqAg/?ref=app