What is the output of the following? “`python from itertools import groupby data = [(‘a’,1),(‘a’,2),(‘b’,3),(‘b’,4),(‘a’,5)] result = {k: list(v) for k, v in groupby(data, key=lambda x: x[0])} print(result) “`

Python Developer Hard

Python Developer — Hard

What is the output of the following? “`python from itertools import groupby data = [(‘a’,1),(‘a’,2),(‘b’,3),(‘b’,4),(‘a’,5)] result = {k: list(v) for k, v in groupby(data, key=lambda x: x[0])} print(result) “`

Key points

  • The groupby function groups data based on a specified key
  • The lambda function x

Ready to go further?

Related questions