0

I need to turn every three values of a list into a new smaller list.

Here's an example of a list

["bob",1,2,3,mike,4,5,6,"jerry",7,8,9,"richard",10,11,12]

I want it to look like:

[["bob",1,2,3],["mike",4,5,6],["jerry",7,8,9],["richard",10,11,12]]

How would I go about doing that?

I've tried using a for loop but I haven't had success.

list=#The first list above
n=3
count=0
for item in list:
      [list[count::n]]
      count+=1

I've seen other versions of this question with a list of numbers but I think the strings in mine might mess up those solutions.

0 Answers0