<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<tt>On 10/4/2011 10:07 AM, lina wrote:</tt>
<blockquote
cite="mid:CAG9cJmmqJd51Pt6h81kGyn0A7yDgA10iCbW5Js8rayJXxX7i=Q@mail.gmail.com"
type="cite"><tt>want to do a statistic of the concurrence of E,<br>
</tt>
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
0.8ex; border-left: 1px solid rgb(204, 204, 204);
padding-left: 1ex;">
<div class="gmail_quote">
<div><tt>namely,<br>
how many times the E showed up,<br>
<br>
so the first column is 1, second column and then
following. <br>
<br>
Thanks,</tt>
<tt><br>
<br>
I have one, which showed something like:<br>
<br>
<br>
<br>
tokens=['E']</tt>
<div class="im"><tt><br>
result=[]<br>
filedata = open("try.xpm")<br>
</tt></div>
<tt>text=filedata.readlines()</tt>
<div class="im"><tt><br>
for line in text: <br>
result.append({t:line.count(t) for t in tokens})
<br>
<br>
for index,r in enumerate(result):
<br>
print(index,"-----",r)<br>
<br>
</tt></div>
<tt>The error message is:</tt>
<div class="im"><tt><br>
<br>
result.append({t:line.count(t) for t in tokens})<br>
^<br>
SyntaxError: invalid syntax<br>
</tt></div>
</div>
</div>
</blockquote>
</div>
</blockquote>
<tt>You are tryng to use a list comrehensioin for the dictionary
value, without the []. Try this:<br>
<br>
result.append({t:[line.count(t) for t in tokens]})<br>
<br>
You should then see:<br>
0, '-----', {'E': [1]})<br>
(1, '-----', {'E': [2]})<br>
(2, '-----', {'E': [2]})<br>
<br>
which is not what you want!<br>
<br>
As requested before, show us the output you do want. Not a
description but the actual output.<br>
<br>
-- Bob Gailer
919-636-4239
Chapel Hill NC</tt>
</body>
</html>