Re: gather information from various files efficiently

2004-12-15 Thread Paul McGuire
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

Re: gather information from various files efficiently

2004-12-14 Thread Simon Brunning
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.

Re: gather information from various files efficiently

2004-12-14 Thread Fernando Perez
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

Re: gather information from various files efficiently

2004-12-14 Thread Mike Meyer
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,

Re: gather information from various files efficiently

2004-12-13 Thread Keith Dart
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

gather information from various files efficiently

2004-12-13 Thread Klaus Neuner
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

Re: gather information from various files efficiently

2004-12-13 Thread Kent Johnson
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

Re: gather information from various files efficiently

2004-12-13 Thread Richie Hindle
[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] --

Re: gather information from various files efficiently

2004-12-13 Thread Peter Hansen
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?