Go through a vector up to a certain number of indexes and form a list with the values

0

I have the following vector:

a = [10, 10, 10, 10, 10, 20, 20, 20, 20, 20]

I need every 5 indexes to list them.

It would look like this:

b = [(10, 10, 10, 10, 10), (20, 20, 20, 20, 20)]

I think it's something simple, but I can not execute.

Could anyone help me?

    
asked by anonymous 20.08.2017 / 03:05

1 answer

1

An alternative, see working here .

a = [10, 10, 10, 10, 10, 20, 20, 20, 20, 20]
b = []
t =[] # Temporario

i = 1
for numero in a:
  t.append(numero)
  if i == 5:
    i = 0 # Volta a contagem do zero
    b.append(tuple(t))
    t = [] # Limpa
  i += 1 # Incrementa +1

print(b)
    
20.08.2017 / 04:12