On 10/4/2011 10:07 AM, lina wrote:
want to do a statistic of the concurrence of E,

    namely,
    how many times the E showed up,

    so the first column is 1, second column and then following.

    Thanks,

    I have one, which showed something like:



    tokens=['E']

    result=[]
    filedata = open("try.xpm")
    text=filedata.readlines()

    for line in text:
        result.append({t:line.count(t) for t in tokens})

    for index,r in enumerate(result):
        print(index,"-----",r)

    The error message is:


        result.append({t:line.count(t) for t in tokens})
                                         ^
    SyntaxError: invalid syntax

You are tryng to use a list comrehensioin for the dictionary value, without the []. Try this:

   result.append({t:[line.count(t) for t in tokens]})

You should then see:
0, '-----', {'E': [1]})
(1, '-----', {'E': [2]})
(2, '-----', {'E': [2]})

which is not what you want!

As requested before, show us the output you do want. Not a description but the actual output.

-- Bob Gailer 919-636-4239 Chapel Hill NC
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to