[Tutor] arrary stastic
lina
lina.lastname at gmail.com
Tue Oct 4 18:35:43 CEST 2011
On Wed, Oct 5, 2011 at 12:26 AM, Dave Angel <d at davea.name> wrote:
> On 10/04/2011 12:01 PM, bob gailer wrote:
>
>> 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
>>
>> I'll second Bob's request, and go further: Move this discussion into
> the original thread, and repeat in one place your assumptions for input,
> requirements for
I will move back to the original thread.
Thanks for your suggestions.
> output, the code you're using and how the output differs from what you
> expect.
>
> You also need to give your target python version, and if you're currently
> getting an exception the full stack trace. Finally, if it's relevant, the
> operating system as well.
>
> I think you've given almost all of this, except the python version and the
> expected file output.
>
I guess mainly choose python3, the default python is $ python
Python 2.6.7 (r267:88850, Jul 10 2011, 08:11:54)
[GCC 4.6.1] on linux2
python
python2.5
python2.6
python2.7
python3
python3.1
python3.2
python3.2mu
>
> --
>
> DaveA
>
>
--
Best Regards,
lina
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111005/d4a1a4d3/attachment.html>
More information about the Tutor
mailing list