2018-05-12 11:37:19 +02:00
|
|
|
#!/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):
|
2018-05-29 18:50:29 +02:00
|
|
|
list1=[]
|
|
|
|
for i in string1:
|
|
|
|
if i in string2:
|
|
|
|
list1.append(i)
|
|
|
|
for i in string2:
|
|
|
|
if i in string1:
|
|
|
|
list1.append(i)
|
|
|
|
list1=list(set(list1))
|
|
|
|
list1.sort()
|
|
|
|
list1.pop(0)
|
|
|
|
return list1
|
2018-05-12 11:37:19 +02:00
|
|
|
|
|
|
|
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))
|