Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Comprehensions in Python are pretty handy, but they can look weird sometimes. This is filtering out `None`, empty string, etc values from a list.

It is iterating over a list (tokens) and creating a temporary variable (token). It tests the truthyness of it (if token), which means None and '' will return False and thus be excluded, and then returns it (the first token).



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: