array constructor & atof()
Tom Holroyd
tomh at po.crl.go.jp
Mon Feb 28 21:30:47 EST 2000
On Mon, 28 Feb 2000, Michael Tiomkin wrote:
> Well, the following worked for me (forcing list copy):
> >>> a=[[0]*4]*4
> >>> b=map(lambda x: x+[],a)
Hrm. Or m = map(lambda x: x[:], [[0] * 4] * 4). That's halfway decent.
Thanks (and to the other constructive suggestions).
> In some countries, 123,456 means 1.23456e5
That's a valid reason.
> If you use a delimiter on a list of numbers, you can use splitfields
> from string module. BTW, Python could have a better split function,
> like that in awk, or at least with a string of possible delimiters,
> and the meaning of choosing the maximal string of a type [a1...an]*.
Now *there* is an excellent point -- my problem would easily have been
solved if I could have said 'string.split(str, ",;")' and this makes
even more sense since 'string.split(str)' means *any* whitespace.
Unfortunately the former already means that the delimiter is the full
string ",;" rather than any of them. So:
>>> import re
>>> re.split(", |; ", "123.45, this; and that")
['123.45', 'this', 'and that']
Yea, that's the ticket.
Dr. Tom Holroyd
"I am, as I said, inspired by the biological phenomena in which
chemical forces are used in repetitious fashion to produce all
kinds of weird effects (one of which is the author)."
-- Richard Feynman, _There's Plenty of Room at the Bottom_
More information about the Python-list
mailing list