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
|
|
|
"""
|
|
|
|
|
|
|
|
def common_chars(string1, string2):
|
z1, z2, z3, z4, z5, z6, z7, z8, z9, z10, z11
2017-11-29 00:58:00 +01:00
|
|
|
sl = []
|
|
|
|
for i in string1:
|
|
|
|
for j in string2:
|
|
|
|
if i==j:
|
|
|
|
sl.append(i)
|
|
|
|
sly = [x for x in sl if x != ' ']
|
|
|
|
sly.sort()
|
|
|
|
slz = []
|
|
|
|
for z in sly:
|
|
|
|
if z not in slz:
|
|
|
|
slz.append(z)
|
|
|
|
return slz
|
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))
|