O'Reilly Forums: Unique_James Gives Syntax Error? - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Unique_James Gives Syntax Error? IDLE can't figure it out

#1 User is offline   Big_Pug 

  • New Member
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 29-December 12

Posted 03 January 2013 - 01:28 PM

My code looks like this... IDLE3 highlights 'unique_james' and calls it a syntax error. I tried moving unique_james=[] around, and instead it highlighted the ':' in 'for each_item in james:'

------

with open('james.txt') as jaf:
data = jaf.readline()
james = data.strip().split(',')

with open('julie.txt') as juf:
data = juf.readline()
julie = data.strip().split(',')

with open('sarah.txt') as saf:
data = saf.readline()
sarah = data.strip().split(',')

with open('mikey.txt') as mif:
data = mif.readline()
mikey = data.strip().split(',')

def sanitize(time_string):
if '-' in time_string:
splitter = '-'
elif ':' in time_string:
splitter = ':'
else:
return(time_string)
(mins, secs) = time_string.split(splitter)
return(mins + '.' + secs)

james = [sorted([sanitize(t) for t in james])

unique_james = []
for each_item in james:
if each_item not in unique_james:
unique_james.append(each_item)


print(unique_james[0:3])

------

What did I do wrong? :(
0

#2 User is offline   Big_Pug 

  • New Member
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 29-December 12

Posted 03 January 2013 - 03:50 PM

Ahhhhh... I missed a parentheses. So nevermind that. :P

I always get my parentheses wrong! Ohohoho...
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users