1

I have a list of random float values. Here's an example:

my_list = [56.23, 9.1, 856.1, 158.31, 84.15, 63.91, 3.46, 5.1, 5, 6, 31, 84]

Except, my list (when generated) is hundreds of variables long, always divisible by 6. I'm trying to find a quick way (that doesn't involve reversing the list and iterating through new list variables by popping them off one-by-one) to turn my list into a list containing all of the original floats, but paired into groups of six? Here's how it should look given the random list I've created above:

my_list = [56.23, 9.1, 856.1, 158.31, 84.15, 63.91, 3.46, 5.1, 5, 6, 31, 84]
new_list = some_awesome_function(my_list)
print(new_list)

This new_list variable should print:

new_list = [[56.23, 9.1, 856.1, 158.31, 84.15, 63.91], [3.46, 5.1, 5, 6, 31, 84]]

Simply the same list, but it groups every six variables into its own group within the group. Any idea, folks? This would be very much appreciated.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
T.J. Kolberg
  • 47
  • 1
  • 6

0 Answers0