Advertisement
here2share

# remove_empty_strings_from_a_list.py

Sep 5th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.33 KB | None | 0 0
  1. # remove_empty_strings_from_a_list.py
  2.  
  3. str_list = ["", None, '', 0, "Hi", '', '', 'Python!', '', False, 123]
  4. str_list = [x for x in str_list if x != '']
  5. print str_list
  6.  
  7. # many times faster, but might be an overkill...
  8.  
  9. mylist = ["", None, '', 0, "Hi", '', '', 'Python!', '', False, 123]
  10. mylist = filter(None, mylist)
  11. print mylist
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement