1
0
forked from tdwojak/Python2018
Python2018/labs02/task11.py
2018-06-02 21:24:05 +02:00

37 lines
904 B
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Napisz funkcję common_chars(string1, string2), która zwraca alfabetycznie
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.
"""
def common_chars(string1, string2):
wspolne = []
string1 = string1.replace(' ', '')
string2 = string2.replace(' ', '')
znaki_z_1 = set(string1)
znaki_z_2 = set(string2)
for x in znaki_z_1:
if x in znaki_z_2:
wspolne.append(x)
return sorted(wspolne)
def tests(f):
inputs = [["this is a string", "ala ma kota"]]
outputs = [['a', 't']]
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))