Search This Blog

Python: list comprehension

  • To transform a list to another:

    list2 = [ unicode(e.strip()) for e in list1 ]
  • To transform a list to another conditionally:

    list2 = [ unicode(e.strip()) if e is not None else '' for e in list1 ]

No comments:

Post a Comment