1

I'm trying to convert a spell checker built in Python 2 to Python 3. I'm having trouble understanding this line.

outlist = sorted(as_list, key=lambda (term, (freq, dist)): (dist, -freq))

I've found a couple of tuple unpacking questions and answers, but I'm having trouble understanding what is actually happening and how to convert this particular line.

martineau
  • 119,623
  • 25
  • 170
  • 301
JD L
  • 63
  • 9
  • Unfortunately it's not more a feature in Python 3. Use a named function and a destructuring assignment if you want nice argument names, or something like `lambda x: (x[0][1], -x[0][0])`. – 9000 Aug 14 '17 at 23:26

0 Answers0