forked from tdwojak/Python2017
task07_rev + task11_rev upload
This commit is contained in:
parent
1cdc7bbede
commit
94a4de59d7
33
Homework/labs02/task11_rev.py
Normal file
33
Homework/labs02/task11_rev.py
Normal 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))
|
37
Homework/labs02/task_07_rev.py
Normal file
37
Homework/labs02/task_07_rev.py
Normal 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))
|
Loading…
Reference in New Issue
Block a user