-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisj_proj2_xturyt00.py
49 lines (35 loc) · 1.66 KB
/
isj_proj2_xturyt00.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python3
# ukol za 2 body
def she_says_he_says(she_says):
"""Replaces y/i, removes spaces, returns reversed
>>> she_says_he_says('ma rymu')
'umiram'
"""
phonetic_she_says = she_says.replace('y','i')
compact = phonetic_she_says.replace(' ','')
he_says = compact[::-1]
return he_says
# ukol za 3 body
def solfege(title_hymn):
"""Partitions the input string to (an optional) title, ': ', and the hymn,
takes a sublist starting from the first string, skipping always two
other strings, and ending 3 strings from the end, returns the result
as a string with ', ' as a separator
>>> solfege('Hymn of St. John: Ut queant laxis re sonare fibris mi ra gestorum fa muli tuorum sol ve polluti la bii reatum Sancte Iohannes')
'Ut, re, mi, fa, sol, la'
>>> solfege('Ut queant laxis re sonare fibris mi ra gestorum fa muli tuorum sol ve polluti la bii reatum Sancte Iohannes')
'Ut, re, mi, fa, sol, la'
"""
# the input string partitioned to the title (if given) and the actual hymn
possible_title, sep, hymn = title_hymn.rpartition(':') #cuts title from : and returns hymn
# the hymn as a list of strings separated by ' '
hymn_list = hymn.split() # creates list using space as separator
# skipping always two strings, and ending 3 strings from the end
skip2 = hymn_list[:-3:3] #returns every third, skipping last 3
# the skip2 list as a string, ', ' as a separator
skip2_str = ', '.join(skip2) # converts list to string
return skip2_str
if __name__ == "__main__":
import doctest
doctest.testmod()
pass