My personal favorite would be ruby's iterators and blocks.
Instead of writing a bunch of repetitive list comprehensions or
defining a bunch of utility functions, you just use the iterators
supported by container objects.
For instance,

[f(x) for x in y]

could be written in Ruby as

y.collect |x| do
  #body of f
end

You don't have to use a lambda or define f() externally.
Best of all, Ruby's containers come with many iterators for common
cases builtin.

Joseph Garvin wrote:
> As someone who learned C first, when I came to Python everytime I read
> about a new feature it was like, "Whoa! I can do that?!" Slicing, dir(),
> getattr/setattr, the % operator, all of this was very different from C.
>
> I'm curious -- what is everyone's favorite trick from a non-python
> language? And -- why isn't it in Python?
>
> Here's my current candidate:
>
> So the other day I was looking at the language Lua. In Lua, you make a
> line a comment with two dashes:
>
> -- hey, this is a comment.
>
> And you can do block comments with --[[ and ---]].
>
> --[[
> hey
> this
> is
> a
> big
> comment
> --]]
>
> This syntax lets you do a nifty trick, where you can add or subtract a
> third dash to change whether or not code runs:
>
> --This code won't run because it's in a comment block
> --[[
> print(10)
> --]]
>
> --This code will, because the first two dashes make the rest a comment,
> breaking the block
> ---[[
> print(10)
> --]]
>
> So you can change whether or not code is commented out just by adding a
> dash. This is much nicer than in C or Python having to get rid of """ or
> /* and */. Of course, the IDE can compensate. But it's still neat :)

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

Reply via email to