Created
April 12, 2012 02:54
-
-
Save falsetru/2364369 to your computer and use it in GitHub Desktop.
code-kata-pickakin
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
# http://ilker.de/code-kata-pickakin | |
def dsq(product_code): | |
return product_code[0] | |
def partition(common_dsq, orig_list): | |
new_list = set() | |
akin_list = set() | |
for x in orig_list: | |
if dsq(x) in common_dsq: | |
akin_list.add(x) | |
else: | |
new_list.add(x) | |
return akin_list, new_list | |
def solve(ceo_list, control_list): | |
common_dsq = set(map(dsq, ceo_list)) & set(map(dsq, control_list)) | |
akin_list_1, new_ceo_list = partition(common_dsq, ceo_list) | |
akin_list_2, new_control_list = partition(common_dsq, control_list) | |
return akin_list_1 | akin_list_2, new_ceo_list, new_control_list | |
ceo_list = ['A1','B1','A2','A3','C1','D1','E1','E2'] | |
control_list = ['F1','D2','B2','B3','A4'] | |
got = solve(ceo_list, control_list) | |
assert got == ( | |
{'A1','B2','A2','A3','B3','A4','D1','D2','B1'}, | |
{'C1','E1','E2'}, | |
{'F1'} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment