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
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
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
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
somewhere somehow :) Though I *a
Thanks Kent, for breaking the bad news. I'm not angry, just terribly,
terribly disappointed. :)
"From http://www.unicode.org/unicode/reports/tr18/ I see that \p{L} is
intended to select Unicode letters, and it is part of a large number of
selectors based on Unicode character properties."
Yeah,
Does Python support the Unicode-flavored class-specifications in
regular expressions, e.g. \p{L} ? It doesn't work in the following
code, any ideas?
-
#! /usr/local/bin/python
""" usage: ./uni_read.py file
"""
import codecs
import re
text = codecs.open(sys.argv[1], mode='r', encoding='u
I think I understand this sorting-a-list 'in place' stuff, and things
of that kind (reversing for example); but I am finding it very
difficult to get used to, since sorting a list doesn't return the
sorted list as a value, but simply does the work as a side effect.
The place where it really
I just discovered the following behavior, but can't find any
documentation about it:
>>> list = []
>>> list = list + 'abc'
Traceback (most recent call last):
File "", line 1, in ?
TypeError: can only concatenate list (not "str") to list
but:
>>> list = []
>>> list += 'abc'
>>> list
['a
On Feb 14, 2006, at 3:46 PM, Andre Roberge wrote:
> [2**i for i in [1, 2, 3, 4]]
Ah yes, I'm sorry, I was thinking of the most general case, where the
arguments are
two arbitrary lists. My example was too specific.
Is there a way to do something like the following in a list
comprehension?
I read somewhere that the function 'map' might one day be deprecated
in favor of list comprehensions.
But I can't see a way to do this in a list comprehension:
>>> map (pow, [2, 2, 2, 2], [1, 2, 3, 4])
[2, 4, 8, 16]
Is there a way?
Cheers,
Mike
___
10 matches
Mail list logo