1
0
forked from tdwojak/Python2017

task07_rev + task11_rev upload

This commit is contained in:
s45153 2018-01-22 00:07:37 +00:00
parent 1cdc7bbede
commit 94a4de59d7
2 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1,33 @@
#!/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):
temp=[]
str1 = list(set(string1.replace(' ', '')))
str2 = list(set(string2.replace(' ', '')))
for i in str1:
if i in str2:
temp.append(i)
temp.sort()
return temp
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))

View File

@ -0,0 +1,37 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#text = [["aaa"], ["bbb"], ["this is another string"]]
#text = "aaa"
text = [["this is a string"], ["this is another string"]]
def char_sum(text):
if isinstance(text, str):
def form_ascii(text):
print(sum(map(ord, text)))
return form_ascii(text)
elif isinstance(text, list):
def ascii_list(text):
loc = [sub_list[0] for sub_list in text]
for i in loc:
print(sum(map(ord, i)))
return ascii_list(text)
else:
print("try harder")
char_sum(text)
def tests(f):
inputs = [["this is a string"], ["this is another string"]]
outputs = [1516, 2172]
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(char_sum))