Huffman coding comparison
Leandro Lucarella
llucax at gmail.com
Fri May 28 16:31:29 PDT 2010
bearophile, el 28 de mayo a las 18:01 me escribiste:
> For me for one thing the D program is better than the Python version:
> the Python std lib doesn't define a mutable named tuple like that one in
> D2 (there is only one immutable and dynamically typed one), this forces
> the Python code to use all those [0] and [1:]. Anonymous structures
> sometimes make Python code shorter, but they can be less explicit too.
> Of course it's easy to define in Python a function like Tuple of Phobos2
> that accepts optional field names too.
Just for fun :)
def NamedTuple(*fields):
class T:
def __init__(self, *args):
for i in range(len(args)):
setattr(self, fields[i], args[i])
return T
Pair = NamedTuple("symb", "code")
Block = NamedTuple("freq", "pair")
p = Pair(1, 2)
b = Block(3, p)
print p.symb, p.code, b.freq, b.pair.symb, b.pair.code
> I will keep missing array comprehensions in D. In the meantime other
> languages have got some forms of them (but Python ones use the best
> syntax still).
They are wonderful, and it's *very* hard to get used to live in a language
that doesn't support them once you start using it often.
PS: Sorry about the Python-love mail... =P
--
Leandro Lucarella (AKA luca) http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
"Lidiar" no es lo mismo que "holguear"; ya que "lidiar" es relativo a
"lidia" y "holguear" es relativo a "olga".
-- Ricardo Vaporeso
More information about the Digitalmars-d
mailing list