
fname = raw_input("Enter file name: ")
fh = open(fname)
lst = list()
for line in fh:
item=line.split()
for i in item:
if i not in lst:
lst.append(i)
print sorted(lst)
File "<ipython-input-1-3295166245ed>", line 9
print sorted(lst)
^
SyntaxError: invalid syntax
fname = raw_input("Enter file name: ")
if len(fname) < 1 : fname = "mbox-short.txt"
fh = open(fname)
count = 0
k=[]
for line in fh:
line=line.rstrip()
if not line.startswith("From"):continue
word=line.split()
if len(word)>5:
print word[1]
count=count+1
print "There were", count, "lines in the file with From as the first word"
File "<ipython-input-2-1ffc388e208b>", line 12
print word[1]
^
SyntaxError: Missing parentheses in call to 'print'
#week five
name = raw_input("Enter file:")
if len(name) < 1 : name = "mbox-short.txt"
handle = open(name)
c=dict()
for line in handle:
if line.startswith("From") and len(line.split())>6:
line=line.rstrip()
m=line.split()[1]
c[m]=c.get(m,0)+1
bigcount=None
bigworf=None
for word,count in c.items():
if bigcount is None or count>bigcount:
bigword=word
bigcount =count
print bigword,bigcount
File "<ipython-input-1-b4d41c4b1406>", line 17
print bigword,bigcount
^
SyntaxError: Missing parentheses in call to 'print'
name = raw_input("Enter file:")
if len(name) < 1 : name = "mbox-short.txt"
handle = open(name)
c=dict()
l=list()
for line in handle:
if line.startswith("From") and len(line.split())>6:
line=line.rstrip()
m=line.split()[5][0:2]
c[m]=c.get(m,0)+1
for v,k in c.items():
l.append((v,k))
l.sort()
for v,k in l:
print v,k
File "<ipython-input-6-a4474ccb8d7f>", line 15
print v,k
^
SyntaxError: Missing parentheses in call to 'print'
days = ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')
days[2]
'Wed'




近期评论