From: "Terry Reedy" <tjre...@udel.edu>
On 5/23/2011 1:31 AM, Octavian Rasnita wrote:


I am talking about a simple way of creating a hash/dict from an array,
which is so simple that there should be really a single way to do it, or
very few.

Again, Python has such:

>>> dict([['one',1],['two', 2]])
{'two': 2, 'one': 1}


That is not an array, but a list. An array has a name and we can't do something like the following simple statement in Python:

l = (1, 2)
d = dict(l)

While in Perl we can do:

@l = (1, 2);
%d = @l;

But let's remember from what this discussion started. This is not a Python critique, because each language has its own ways. I just wanted to show that the fact that "there is more than one way to do it" in Perl and that "there is a single way" in Python are just buzzwords, because this was an example where in Python there are many ways to do it while in Perl there is a single way used usually, which is also more simple.

Octavian

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to