They are more limited than similar constructs in some other languages, which compels using named functions in situations where in other languages one might use anonymous ones. On balance, this isn't really a big deal.
Also, its quite possible to support multistatement lambdas within Python's indentation-sensitive structure; the decision not to do so isn't a result of technical limitations but of aesthetic judgements.
Coffeescript is okay, but it's just a little too terse -- it can sometimes be difficult to figure out what's going on.
The lambda syntax is indeed poor; since it forces the function body has to be an expression, it means you have to jump through hoops to get your implementation to be an expression (or give up and define + use a function).
users = [["user1", 500], ["n00b", 15], ["thebestuser", 177]]
return sorted(users, key=get_post_count)
return sorted(users, key=lambda u : u)
get_users_by_posts = lambda : sorted(users, key=lambda u : u)
A better way to do it is to take your core data structure, in this case a user, and turn it into a class, dictionary or named tuple. Classes are the best way - there are all sorts of ways to put a nice interface on them.
def __init__(self, name, post_count):
self.name = name
self.post_count = post_count
return '<User name="%s", post_count="%s">' % (self.name, self.post_count)
def __cmp__(self, other_user):
# larger is better
return -cmp(self.post_count, other_user.post_count)
# set up data
users_ = [["user1", 500], ["n00b", 15], ["thebestuser", 177]]
users = 
for user in users_:
# sort users by post count by default
return sorted(users, key=operator.itemgetter(1))
from functools import partial
from operator import itemgetter
get_users_by_posts = partial(sorted, users, key=itemgetter(1))