Python Forum
Balance integer list into multiple list of fixed value
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Balance integer list into multiple list of fixed value
#2
Try this: start with two empty lists (the list of lists, and the first sub-list). Have a total that is zero.

Now loop through the numbers in the loop you were given. If the number plus the total is ten or less, append that number to the sub-list and add it to the total. Otherwise, append the sub-list to the list of lists, start a new sub-list with that number, and reset the total.

At the end of the loop you will have a sub-list left over. Append that to the list of lists. That should be that.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
RE: Balance integer list into multiple list of fixed value - by ichabod801 - Oct-26-2018, 02:27 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Strange behavior list of list mmhmjanssen 3 379 May-09-2024, 11:32 AM
Last Post: mmhmjanssen
  No matter what I do I get back "List indices must be integers or slices, not list" Radical 4 1,305 Sep-24-2023, 05:03 AM
Last Post: deanhystad
  How to do "fixed size" (wrapping) math in Python? AlexanderWulf 13 2,055 Jul-19-2023, 04:13 PM
Last Post: deanhystad
  Fixed colum width for rowLabels i Matplotlib pandabay 0 453 Jun-10-2023, 03:40 PM
Last Post: pandabay
  Delete strings from a list to create a new only number list Dvdscot 8 1,651 May-01-2023, 09:06 PM
Last Post: deanhystad
  List all possibilities of a nested-list by flattened lists sparkt 1 965 Feb-23-2023, 02:21 PM
Last Post: sparkt
  Сheck if an element from a list is in another list that contains a namedtuple elnk 8 1,929 Oct-26-2022, 04:03 PM
Last Post: deanhystad
Question Keyword to build list from list of objects? pfdjhfuys 3 1,635 Aug-06-2022, 11:39 PM
Last Post: Pedroski55
  Selling gives me ‘Insufficient balance’ error gerald 3 1,625 Aug-04-2022, 10:16 AM
Last Post: Larz60+
  Split a number to list and list sum must be number sunny9495 5 2,373 Apr-28-2022, 09:32 AM
Last Post: Dexty

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020