Created
February 20, 2020 13:20
-
-
Save dbuteau/3ab303dc9438148e3a0716360ebbadcc to your computer and use it in GitHub Desktop.
tricky python functions
This file contains hidden or 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
#!/usr/bin/env python3 | |
# encoding: utf-8 | |
""" | |
count the number of objects containing attributes values (regex) in list of objects | |
made regex case insensitive | |
""" | |
import re | |
class user: | |
def __init__(self, name, age): | |
self.name = name | |
self.age = age | |
users_list = [user('alex',20),user('nico',20)] | |
sum(bool(re.search('.*le.*', getattr(user,'name'),re.I) ) for user in users_list) | |
# 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment