[Python] How do I use itertools.groupby()?

Discussão em 'Python' iniciado por Stack, Setembro 26, 2024.

  1. Stack

    Stack Membro Participativo

    I haven't been able to find an understandable explanation of how to actually use Python's itertools.groupby() function. What I'm trying to do is this:

    • Take a list - in this case, the children of an objectified lxml element
    • Divide it into groups based on some criteria
    • Then later iterate over each of these groups separately.

    I've reviewed the documentation, but I've had trouble trying to apply them beyond a simple list of numbers.

    So, how do I use of itertools.groupby()? Is there another technique I should be using? Pointers to good "prerequisite" reading would also be appreciated.

    Continue reading...

Compartilhe esta Página