Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
syntax error on list.sort()
#1
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?
Reply
#2
You're missing a close parenthesis (')') on line 5. Always look to the previous line on syntax errors.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
aha!
Thank you!
Reply
#4
You are short one closing parenthesis on the line before (the probs.append... line).
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  sort list of dictionaries by value jacksfrustration 4 262 Jun-21-2024, 08:44 PM
Last Post: deanhystad
  is this really a syntax error? Skaperen 4 435 May-25-2024, 07:31 AM
Last Post: snippsat
  World Clock syntax error OscarBoots 1 348 May-03-2024, 05:20 AM
Last Post: snippsat
  Sort a list of dictionaries by the only dictionary key Calab 2 782 Apr-29-2024, 04:38 PM
Last Post: Calab
  list.sort() returning None SmallCoder14 8 899 Mar-19-2024, 09:49 PM
Last Post: SmallCoder14
  Syntax error for "root = Tk()" dlwaddel 15 1,836 Jan-29-2024, 12:07 AM
Last Post: dlwaddel
Photo SYNTAX ERROR Yannko 3 579 Jan-19-2024, 01:20 PM
Last Post: rob101
  Syntax error while executing the Python code in Linux DivAsh 8 2,053 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Code is returning the incorrect values. syntax error 007sonic 6 1,500 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  syntax error question - string mgallotti 5 1,517 Feb-03-2023, 05:10 PM
Last Post: mgallotti

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020