my-psb/hks/203-sets-of-love.py

47 lines
1.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
# coding: utf8
"""sets-of-love.py"""
def love_meet(bob, alice):
"""
Function documentation
:Tests:
>>> alice = ['', '', '', '', '', '']
>>> bob = ['', '', '', '', '', '']
>>> love_meet(bob, alice)
{'', ''}
"""
meet_districts = [district for district in alice if district in bob]
result = set()
for district in meet_districts:
result.add(district)
return result
def affair_meet(bob, alice, silvester):
"""
Function documentation
:Tests:
>>> alice = ['', '', '', '', '', '', '']
>>> bob = ['', '', '', '', '', '']
>>> silvester = ['VⅢ', '', '', '', '', 'VⅢ']
>>> affair_meet(bob, alice, silvester)
{''}
"""
return {district for district in alice if district in silvester and district not in bob}
if __name__ == "__main__":
import doctest
doctest.testmod()