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-06-02 22:57:30 +02:00
|
|
|
lista = []
|
|
|
|
for a in range(97,123,1):
|
|
|
|
if chr(a) in string1 and chr(a) in string2:
|
|
|
|
lista.append(chr(a))
|
|
|
|
print lista
|
|
|
|
return lista
|
|
|
|
|
|
|
|
|
|
|
|
#print(cmp(string1, string2))
|
|
|
|
#ord(string2)
|
|
|
|
print(ord('a'), 'do', ord('z'))
|
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))
|