0
Good team, I have a method that receives a list and from it creates sub-list and attaches in Buckets:
def indexar(self, keys):
buckets = [[] for _ in range(10)]
for i in keys:
for ii in range(10):
if i % 10 == ii:
buckets[ii].append(i)
When I pass the list:
keys = list(range(0, 100)
Return:
Buckets[0] = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90]
From this I wanted to split all Buckets[] sub-lists to size 3, example:
nova[0] = [[0, 10, 20], [30, 40, 50], [60, 70, 80], [90]]
I’m trying this way:
novo = list()
for i in range(0, len(buckets)):
for ii in range(0, len(buckets[i]), 3):
novo.append(list(buckets[i][ii:ii + 3]))
return novo
Only this way she only slices the sub-lists, but she doesn’t connect. Complete code:
def indexar(self, keys):
buckets = []
for _ in range(10):
buckets.append([])
for i in keys:
for ii in range(10):
if i % 10 == ii:
buckets[ii].append(i)
nova = []
for i in range(0, len(buckets)):
for ii in range(0, len(buckets[i]), 3):
nova.append(list(buckets[i][ii:ii + 3]))
return nova
You could put an example of an input list and an output list you want to get?
– Naslausky
I edited the question, can take a look if it became clearer ?
– jusintique