Michael Broe wrote:
> dict = {}
dict is the name of the builtin dictionary class, so you shouldn't use
it as the name of your dict - you shadow the built-in name. file is also
a built-in name.
>
> L = file[0]
> for R in file[1:]:# move right edge of window across the file
> if not L
My only comment is that this considers spaces and punctuation (like parentheses, brackets, etc.), too, which I assume you don't want seeing as how that has little to do with natural languages. My suggestion would be to remove the any punctuation or whitespace keys from the dictionary after you've
Well coming up with this has made me really love Python. I worked on
this with my online pythonpenpal Kyle, and here is what we came up
with. Thanks to all for input so far.
My first idea was to use a C-type indexing for-loop, to grab a two-
element sequence [i, i+1]:
dict = {}
for i in rang
On Mon, 2006-04-03 at 11:39 -0700, Danny Yoo wrote:
> > You can check if the dictionary key exists prior to assigning to it:
> >
> > >>> if not D.has_key('c'):
> > ...D['c'] = {}
> > >>> D['c']['a'] = 1
>
>
> Hi Victor,
>
> Another approach is to use the badly-named "setdefault()" method whi
> On Wed, 2006-03-29 at 00:15 -0500, Michael Broe wrote:
> You can check if the dictionary key exists prior to assigning to it:
>
if not D.has_key('c'):
> ...D['c'] = {}
D['c']['a'] = 1
And since 2.4?
if 'c' in D: ...
Alan G.
___
Tutor
> You can check if the dictionary key exists prior to assigning to it:
>
> >>> if not D.has_key('c'):
> ...D['c'] = {}
> >>> D['c']['a'] = 1
Hi Victor,
Another approach is to use the badly-named "setdefault()" method which is
a close analogue to Perl's "autovivification" feature:
##
>>>
On Wed, 2006-03-29 at 00:15 -0500, Michael Broe wrote:
> Aha! John wrote:
>
> "Are you sure you haven't mistakenly assigned something other than a
> dict to D or D['d'] ?"
>
> Thanks for the tip! Yup that was it (and apologies for not reporting
> the problem more precisely). I hadn't initiali
Aha! John wrote:
"Are you sure you haven't mistakenly assigned something other than a
dict to D or D['d'] ?"
Thanks for the tip! Yup that was it (and apologies for not reporting
the problem more precisely). I hadn't initialized the nested
dictionary before trying to assign to it. (I think P
Michael Broe wrote:
> I'm playing with the whole idea of creating bigram (digram?)
> frequencies for text analysis and cryptographic and entropy analysis
> etc (this is as much an exercise in learning Python and programming
> as anything else, I realise everything has already been done
> so
On 29/03/06, Michael Broe <[EMAIL PROTECTED]> wrote:
> Well I ran into an interesting glitch already. For a dictionary D, I
> can pull out a nested value using this syntax:
>
> >>> D['b']['a']
> 23
>
> and I can assign to this dictionary using
>
> >>> D['d'] = {'a':7, 'b':0'}
>
> but I can't assi
Well I ran into an interesting glitch already. For a dictionary D, I
can pull out a nested value using this syntax:
>>> D['b']['a']
23
and I can assign to this dictionary using
>>> D['d'] = {'a':7, 'b':0'}
but I can't assign like this:
>>> D['d']['c'] = 1
TypeError: object does not suppor
11 matches
Mail list logo