2017-11-18 16:45:28 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
Napisz funkcję common_chars(string1, string2), która zwraca alfabetycznie
|
2017-11-19 10:42:39 +01:00
|
|
|
uporządkowaną listę wspólnych liter z lańcuchów string1 i string2.
|
|
|
|
Oba napisy będą składać się wyłacznie z małych liter.
|
2017-11-18 16:45:28 +01:00
|
|
|
"""
|
2017-11-27 21:23:07 +01:00
|
|
|
# tablica=[]
|
|
|
|
# def common_chars(string1, string2):
|
|
|
|
# for x in string1:
|
|
|
|
# for x in string2:
|
|
|
|
# tablica.append(x)
|
|
|
|
# return set(tablica)
|
|
|
|
# common_chars("this is a string", "ala ma kota")
|
2017-11-18 16:45:28 +01:00
|
|
|
|
|
|
|
def common_chars(string1, string2):
|
2017-11-27 21:23:07 +01:00
|
|
|
s=set(string1)
|
|
|
|
t=set(string2)
|
|
|
|
intersect1 = s.intersection(t).difference("' '")
|
|
|
|
intersect1 = list(intersect1)
|
|
|
|
intersect1.sort()
|
|
|
|
return intersect1
|
2017-11-18 16:45:28 +01:00
|
|
|
|
2017-11-27 21:23:07 +01:00
|
|
|
#print(type(intersect1))
|
2017-11-18 16:45:28 +01:00
|
|
|
|
|
|
|
def tests(f):
|
2017-11-19 10:42:39 +01:00
|
|
|
inputs = [["this is a string", "ala ma kota"]]
|
|
|
|
outputs = [['a', 't']]
|
2017-11-18 16:45:28 +01:00
|
|
|
|
|
|
|
for input, output in zip(inputs, outputs):
|
|
|
|
if f(*input) != output:
|
|
|
|
return "ERROR: {}!={}".format(f(*input), output)
|
|
|
|
break
|
|
|
|
return "TESTS PASSED"
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
print(tests(common_chars))
|