Klaus Neuner [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Hello,
I need to gather information that is contained in various files.
Like so:
file1:
=
foo : 1 2
bar : 2 4
baz : 3
=
file2:
=
foo : 5
bar : 6
baz
On Tue, 14 Dec 2004 10:40:56 -0500, Peter Hansen [EMAIL PROTECTED] wrote:
Keith Dart wrote:
Sigh, this reminds me of a discussion I had at my work once... It seems
to write optimal Python code one must understand various probabilites of
your data, and code according to the likely scenario.
Keith Dart wrote:
Aye...
the dict.keys() line creates a temporary list, and then the 'in' does a
linear search of the list. Better would be:
try:
dict[a].append(b)
except KeyError:
dict[a] = [b]
since you expect the key to be there most of the time, this method is
most
Simon Brunning [EMAIL PROTECTED] writes:
On Tue, 14 Dec 2004 10:40:56 -0500, Peter Hansen [EMAIL PROTECTED] wrote:
Keith Dart wrote:
Sigh, this reminds me of a discussion I had at my work once... It seems
to write optimal Python code one must understand various probabilites of
your data,
Klaus Neuner wrote:
Hello,
I need to gather information that is contained in various files.
Like so:
file1:
=
foo : 1 2
bar : 2 4
baz : 3
=
file2:
=
foo : 5
bar : 6
baz : 7
=
file3:
=
foo : 4 18
bar
Hello,
I need to gather information that is contained in various files.
Like so:
file1:
=
foo : 1 2
bar : 2 4
baz : 3
=
file2:
=
foo : 5
bar : 6
baz : 7
=
file3:
=
foo : 4 18
bar : 8
Keith Dart wrote:
try:
dict[a].append(b)
except KeyError:
dict[a] = [b]
or my favorite Python shortcut:
dict.setdefault(a, []).append(b)
Kent
--
http://mail.python.org/mailman/listinfo/python-list
[Keith]
Sigh, this reminds me of a discussion I had at my work once... It seems
to write optimal Python code one must understand various probabilites of
your data, and code according to the likely scenario. 8-)
s/Python //g
--
Richie Hindle
[EMAIL PROTECTED]
--
Keith Dart wrote:
Sigh, this reminds me of a discussion I had at my work once... It seems
to write optimal Python code one must understand various probabilites of
your data, and code according to the likely scenario.
And this is different from optimizing in *any* other language
in what way?