• Skip to primary navigation
  • Skip to content
  • Skip to footer
Forget me not
      Alberto Torres Barrán

      Alberto Torres Barrán

      Machine learning at Komorebi

      • Madrid
      • Email
      • Twitter
      • GitHub

      Flat list Python

      La operación de flattening es bastante común a la hora de programar, y consiste en convertir una lista/array en 2 dimensiones como la siguiente:

      [[1,2,3],[4,5,6],[7,8,9]]

      en una lista/array de 1 dimensión:

      [1,2,3,4,5,6,7,8,9]

      En Python, una forma fácil de realizar esta operación en la lista l es:

      [item for sublist in l for item in sublist]

      Fuente: Making a flat list out of list of lists in Python

      Updated: December 14, 2011

      Twitter Facebook LinkedIn
      Previous Next

      You May Also Enjoy

      Git prompt with conda and conda-auto-env

      The Git Team maintains a bash script that sets a message in your prompt displaying the current branch and status. The script can be found here. To install th...

      Benchmark adding together multiple columns in dplyr

      Inspired partly by this and this Stackoverflow questions, I wanted to test what is the fastest way to create a new column using dplyr as a combination of oth...

      Compute correlations using the tidyverse

      This small example aims to provide some use cases for the tidyr package. Let’s generate some example data first: library(lubridate) library(tibble) library(...

      Equivalence between distribution functions in R and Python

      The name for the different functions that work with probability distributions in R and SciPy is different, which is often confusing. The following table list...

      • Feed
      © 2022 Forget me not. Powered by Jekyll & Minimal Mistakes.