Skip to content

Instantly share code, notes, and snippets.

@jorgeas80
Last active October 4, 2018 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorgeas80/6110f31ede55f7708c4450a015b2be94 to your computer and use it in GitHub Desktop.
Save jorgeas80/6110f31ede55f7708c4450a015b2be94 to your computer and use it in GitHub Desktop.
Python one-liner to show a comma-separated string of all the not None elements of a list
from operator import is_not
from functools import partial
fruits = ["apple", "banana", None, "pear", None, "peach", None, None, "grapes"]
# Prints: apple, banana, pear, peach, grapes
print(", ".join(filter(partial(is_not, None), fruits)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment