Python performance notes...
Brett g Porter
BgPorter at NOacmSPAM.org
Sat May 27 23:13:12 CEST 2000
"Moshe Zadka" <moshez at math.huji.ac.il> wrote in message
news:Pine.GSO.4.10.10005271201030.4282-100000 at sundial...
> On Thu, 25 May 2000, Brett g Porter wrote:
> Well, of course, it is much longer in C++, but just for the heck of it,
> here's the real challenge: change it so you'd print
> word lineno lineno .....
> And the words have to be sorted.
// splitter.cpp : Defines the entry point for the console application.
// (c) 2000 Bg Porter
using namespace std;
int main(int argc, char* argv)
int lineNum = 0;
map<string, vector<int> > unique;
lineStream >> newWord;
for (map<string, vector<int> >::iterator i = unique.begin();
i != unique.end(); ++i)
cout << i->first;
for (int j = 0; j < i->second.size(); ++j)
cout << " " << i->second[j];
cout << endl;
Sorted already, by the design of std::map.
> (It took me 3 minutes to take Aahz's script and change it, and I had one
> bug: forgot to import sys and string)
> In 1 more minute, it is possible to change the definition of a word to "a
> consecutive alphabetic characters".
1 minute or less.
In 30 more seconds, it is possible to
> make strings case insensitive,
> and 30 more seconds to disregard "_"s.
If I understood that phrase, I could answer it.
> How much time would it take in C++?
> Remember that map<string, vector<int>> is invalid.
Are you making up rules here? Of course you meant map<string, vector<int> >.
> Moshe Zadka <moshez at math.huji.ac.il>
> http://www.linux.org.il -- we put the penguin in .com
More information about the Python-list