So I wrote this code intended to let the code group different numbers from a list together in a total of n: int
groups
Edit If you do not understand what the purpose of the code is, please look in the comments, I've explained it there. Thank you:)
def calcdifference(lst: list):
for x in lst:
return (x -= x)
print(calcdifference(lst=[4,5,6,4,3,2,3,4,5]))
def grouping(lst: list, n: int):
if calcdifference(x) in list == max(calcdifference(x)):
lst.append(x)
print(grouping(lst=[4,5,6,4,3,2,3,4,5]))
n: int represents the number of groups permitted from one single list, so if n is 3, the numbers will be grouped in (x,...), (x,....) (x,...) If n = 2, the numbers will be grouped in (x,..),(x,...).
However, my code prints out all possible combinations in a list of n elements. But it doesnt group the numbers together. So what I want is: for instance if the input is
[10,12,45,47,91,98,99]
and if n = 2, the output would be
[10,12,45,47] [91,98,99]
and if n = 3, the output would be
[10,12] [45,47] [91,98,99]
What changes to my code should I make?
Note: please refrain from using built in functions or import since I want to use as less built in functions as possible
Important: the code should be able to print n >= len(lst)
combinations for every list provided