This repository has been archived by the owner on May 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproj2.py
44 lines (31 loc) · 1.39 KB
/
proj2.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
#!/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(": ")
# the hymn as a list of strings separated by ' '
hymn_list = hymn.split()
# skipping always two strings, and ending 3 strings from the end
skip2 = hymn_list[:-3:3]
# the skip2 list as a string, ', ' as a separator
skip2_str = ", ".join(skip2)
return skip2_str