gnu-arch-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnu-arch-users] Re: darcs vs tla


From: Catalin Marinas
Subject: [Gnu-arch-users] Re: darcs vs tla
Date: Fri, 12 Nov 2004 10:37:02 +0000
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

Dustin Sallings <address@hidden> writes:
>       IN some cases, yeah, quite a bit.  For example, how many lines
> of the equivalent of this (contrived because I'm too lazy to look for
> anything better) example in C?
>
>       # Create a hash table mapping all of the md5s of the word list
> to the words in the list
>       ht = dict([ (md5.md5(word).hexdigest(), word) for word in
> words])

I wouldn't compare Python with C (maybe assembler with C is a better
comparison) but Python with C++. C++ does not support list
comprehension but you can probably write the above in a single line
(exept for the variable declarations) using the STL library:

for_each(words.begin(), words.end(), add_to_dict(dict));

You would need the add_to_dict functor (callable object) to get the
md5 sum (from a library) and set dict[md5sum] = word.

If you really want to write this on a single line, you could probably
use the Boost library's lambda expressions
(http://boost.org/libs/lambda/doc/index.html).

Catalin





reply via email to

[Prev in Thread] Current Thread [Next in Thread]