Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
1.8 kB
1
Indexable
Never
from collections import namedtuple
characteristic = [
        'wanna_learn_datascience',
        'wanna_learn_ml',
        'wanna_learn_IR',
        'wanna_learn_RecSys',
        'stand_out_from_croud',
        'passionate_with_coding'
        ]
requirements = [
        'finish_assignment',
        'finish_project',
        'keep_practice',
        'study_hard',
        'more_discussion'
        ]

rules = {
        'pass': lambda x: [x[r] for r in requirements],
        'join_clip_lab': lambda x:[x[c] for c in characteristic]
    }

Student = namedtuple("Student", ["name"]+characteristic+requirements)
Student.__new__.__defaults__ = (False,) * len(Student._fields)

# stu = Student._make([True]*len(characteristic+requirements))
s1 = Student(
        **{
        'name':"Leon",
        'finish_assignment':True,
        'finish_project':True,
        'keep_practice':True,
        'study_hard':True,
        'more_discussion':True
        }
    )

s2 = Student(
        **{
        'name':"Victor",
        'finish_assignment':True,
        'finish_project':True,
        'keep_practice':True,
        'study_hard':True,
        'more_discussion':True,
        'wanna_learn_datascience':True,
        'wanna_learn_ml':True,
        'wanna_learn_IR':True,
        'wanna_learn_RecSys':True,
        'stand_out_from_croud':True,
        'passionate_with_coding':True
        }
    )


for stu in [s1, s2]:
    result = all(rules['pass']({_f:stu.__getattribute__(_f) for _f in stu._fields}))
    result = "Student {} can {} WSM".format(stu.name,"pass" if result == True else "fail") 
    print(result)
    result = all(rules['join_clip_lab']({_f:stu.__getattribute__(_f) for _f in stu._fields}))
    result = "Student {} {} join clip_lab".format(stu.name,"can" if result == True else "can't") 
    print(result)