Friday, July 02, 2021

Flat list

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

In javascript:

let flatList = arr.flat()


In python, my trick is walrus operator:

flat_list = []
[flat_list:=flat_list+sub for sub in arr]

 




No comments: