I'm new to python.
I'm trying to create another list from a big one just with 3 elements of that list at a time.
I'm trying this:
my_list = ['test1,test2,test3','test4,test5,test6','test7,test8,test9','test10,test11,test12']
new_three = []
for i in my_list:
item = my_list[int(i):3]
new_three.append(item)
# here I'll write a file with these 3 elements. Next iteration I will write the next three ones, and so on...
I'm getting this error:
item = my_list[int(i):3]
ValueError: invalid literal for int() with base 10: 'test1,test2,test3'
I also tried:
from itertools import islice
for i in my_list:
new_three.append(islice(my_list,int(i),3))
Got the same error. I cannot figure out what I'm doing wrong.
EDIT:
After many tries with help here, I could make it.
listrange = []
for i in range(len(li)/3 + 1):
item = li[i*3:(i*3)+3]
listrange.append(item)