Last active
October 7, 2016 09:26
-
-
Save karnikamit/2052f60ba2b23b38f9d5b24f68b9dfc6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Get both a and b attributes, here 0 is a valid value. | |
Don't use comparison==0 | |
What if c = '', its invalid! | |
""" | |
class A(object): | |
a = 1 | |
b = 0 | |
c = '' | |
d = None | |
a_obj = A() | |
a_list = ['a', 'b', 'c', 'd'] | |
if __name__ == '__main__': | |
filtered_list = filter(lambda x: getattr(a_obj, x, None) is not None, a_list) | |
print filtered_list # ['a', 'b', 'c'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@srinivas-adivi
Thank you