Page List

Wednesday, May 9, 2012

Convert list of lists to single list

This example is based on a Udacity CS262 discussion forum post.

  messedUp = [['one'], ['two'],['three'], ['four']]
  return [item for inner in messedUp for item in inner]
  
  Result:   ['one', 'two', 'three', 'four']