I solved the following Python exercise:
Implement a function that receives a list of length lists and return a list of one dimension.
The solution I was able to do was as follows:
#!/usr/bin/env python
#-*- coding: utf-8 -*-
def list_unifier(lista_de_listas):
lista_unificada = []
for i in range(0, len(lista_de_listas)):
for j in range(0, len(lista_de_listas[i])):
lista_unificada.append(lista_de_listas[i][j])
return lista_unificada
print list_unifier([[1, 2], [3, 4, 5], [], [6, 7]])
Output:
[1, 2, 3, 4, 5, 6, 7]
The question is, would this be the best way to do it? I found it to be very prolix.
I was thinking of something involving for i in lista_de_listas
or something.