1
0
forked from tdwojak/Python2018
Python2018/labs02/task11.py
2018-05-30 11:37:18 +02:00

39 lines
975 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):
lista = []
result = []
for i in range(len(string1)):
lista.append(string1[i])
for j in range(len(string2)):
if string2[j] in lista:
result.append(string2[j])
nowa = list(set(result))
for i in nowa:
if ord(i) == 32:
nowa.remove(i)
nowa.sort()
return nowa
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))