News for hackers. Stuff that matters.
Re:Python 3.5.0 by paulsutter on Monday September 14, 2015 @01:21AM (#10213734)
At first glance, parameter tuple unpacking seems like a silly hack that was wisely removed, explained here http://legacy.python.org/dev/peps/pep-3113/

What are the cases where you use it / rely on it?

Re:Python 3.5.0 by wfunction on Monday September 14, 2015 @03:26AM (#10213963)
> What are the cases where you use it / rely on it?

Basically any time I need to unpack inside a lambda (e.g. functional programming) and have to use something like itertools.groupby(), I run into trouble with Python 3. For example:

  from itertools import groupby
  def groupby_unsorted(items, key):
    return map(lambda (g, l): (g, map(lambda (k, v): v, l)), groupby(sorted(map(lambda v: (key(v), v), items)), lambda (k, v): k))
  print(groupby_unsorted([1, 2, 3, 4], lambda v: v % 2))
Never ran into problems with it either.
Re:Python 3.5.0 by azag0 on Monday September 14, 2015 @07:04PM (#10218062)
Python has comprehensions for this style of programming:

    def groupby_unsorted(iterable, key):
        return [(k, [v for k, v in g])
                for k, g in
                groupby(sorted((key(v), v) for v in iterable),
                        lambda item: item[0])]
    print(groupby_unsorted([1, 2, 3, 4], lambda v: v % 2))
Re:Python 3.5.0 by wfunction on Tuesday September 15, 2015 @05:00PM (#10223173)
Yes, list comprehensions can take care of some of these, but you're completely missing the entire point.

The point was that writing something like

  lambda item: item[0]
in your code is inferior to

  lambda (k, v): k
in terms of readability and comprehensibility. It is both longer and it also doesn't document the fact that the item is semantically a key-value pair.

The problem is not (and has never been) whether something is "necessary" or "possible". Tuple unpacking obviously completely unnecessary to begin with, it has nothing to do with whether this is done in a parameter or not. The problem is whether the code is expressed better via unpacking.

Re:Python 3.5.0 by aldanor on Monday September 14, 2015 @04:40AM (#10214136)
But tuple unpacking inside lambdas is actually supported in Python 3, isn't it?
Re:Python 3.5.0 by wfunction on Monday September 14, 2015 @07:02AM (#10214507)
Could you give me an example of what you mean?