def chunks(lst, n):
          """Yield successive n-sized chunks from lst."""
          for i in range(0, len(lst), n):
              yield lst[i:i + n]

      Python language logoSplit a list into sublists

      Python public recipes

      Split a list into multiple sublists.

      Example ot use

      sublists = chunks(mylist, 3)

      will return a split of the initial mylist into lists of at most 3 elements.


        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.