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
  list.sort() returning None SmallCoder14 8 526 Mar-19-2024, 09:49 PM
Last Post: SmallCoder14
  Syntax error for "root = Tk()" dlwaddel 15 1,148 Jan-29-2024, 12:07 AM
Last Post: dlwaddel
Photo SYNTAX ERROR Yannko 3 369 Jan-19-2024, 01:20 PM
Last Post: rob101
  Sort a list of dictionaries by the only dictionary key Calab 1 486 Oct-27-2023, 03:03 PM
Last Post: buran
  Syntax error while executing the Python code in Linux DivAsh 8 1,540 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Code is returning the incorrect values. syntax error 007sonic 6 1,204 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  syntax error question - string mgallotti 5 1,283 Feb-03-2023, 05:10 PM
Last Post: mgallotti
  Syntax error? I don't see it KenHorse 4 1,236 Jan-15-2023, 07:49 PM
Last Post: Gribouillis
  Syntax error tibbj001 2 880 Dec-05-2022, 06:38 PM
Last Post: deanhystad
  Python-for-Android:p4a: syntax error in main.py while compiling apk jttolleson 2 1,828 Sep-17-2022, 04:09 AM
Last Post: jttolleson

Forum Jump:

User Panel Messages

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