Python Forum

Full Version: syntax error on list.sort()
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I'm trying to sort a list of floats by descending order, and I am not sure why I'm getting a syntax error. I am using exactly what I found online.
probs = []
n = int(input())

for i in range(n): 
    probs.append(float(input().split()[1])

probs.sort(reverse = True) #also tried newprobs = sorted(probs, reverse=True)

tot = 0

for k in range(n):
    tot += probs[k] * (k + 1)
    
print(tot)
What am I missing? Isn't that the right syntax?
You're missing a close parenthesis (')') on line 5. Always look to the previous line on syntax errors.
aha!
Thank you!
You are short one closing parenthesis on the line before (the probs.append... line).