groupby () + comprehension list + lambda
This task can be accomplished using a combination of the above functions. In doing so, we group the elements using groupby (), and the decision to group the logic of the elements is made as a lambda function.
code > Output:
The original list is: [`gfg`,` is `,` best`, `and`,` is`, `popular`] Resultant list after grouping: [[` gfg`], [`best`,` and`], [`popular`]]