Epitaph of John Laird McCaffery (1940-1995), who is buried in the Mount Royal Cemetery in Montreal (Canada):
The text was written jointly by his ex-wife and his mistress. Read the first letter of each line …
Python has a built-in function isinstance(object, data type). The function returns a Boolean value, that indicates whether the given object belongs to the given data type.
>>> value = 1
>>> type(value)
<class 'int'>
>>> isinstance(value, int)
True
>>> isinstance(value, float)
False
>>> isinstance(value, list)
False
An acrostic is a poem or other form of writing in which the first letter, syllable or word of each line, paragraph or other recurring feature in the text spells out a word or a message. Asked:
Write a function selection to which two arguments must be passed: a string that contains a line of a poem and a sequence of numbers $$n_1, n_2, \ldots, n_m$$ as a list or tuple, where $$n_i \in \mathbb{N}_0$$ ($$i = 1, 2, \ldots, m$$) applies. The function must return the string that is formed by the characters $$k_1k_2\ldots k_m$$. Where $$k_i$$ ($$i = 1, 2, \ldots, m$$) represents the character at position $$n_i$$ in the given line. When determining the position of a character in a line, the white space is ignored (spaces, tabs and new lines) and the first character that is not a white character is in position 1. If the line contains less than $$n_i$$ (niet-witruimte) characters, then $$k_i$$ is ignored.
Use the function selection to write a function acrostic to which a file name must be passed. The file name refers to the tet file that contains the lines of a poem. The function also has a second optional parameter positions to which a sequence of integers $$n_1, n_2, \ldots, n_m$$ can be passed as a list or tuple, where $$n_i \in \mathbb{N}_0$$ ($$i = 1, 2, \ldots, m$$) applies. If this sequence counts only one integer $$n_1$$, then the value $$n_1$$ can also be passed as integer to the parameter positions. The default value of the parameter positions is 1. The function should return the string that is formed by selecting the characters in the given positions of each line of the poem (cf. function selection) and putting all these characters after each other.
In the following example session we assume that the files in_memoriam.txt1 and maude.txt2 are in the current directory.
>>> selection('Free your body', [1])
'F'
>>> selection('Unfold your powerful wings', [5, 12])
'lo'
>>> selection('Climb up the highest mountains', [15, 6, 11])
'euh'
>>> selection('Kick your feet up in the air', [500, 250, 10, 2])
'ei'
>>> acrostic('in_memoriam.txt')
'FUCKYOU'
>>> acrostic('in_memoriam.txt', 1)
'FUCKYOU'
>>> acrostic('in_memoriam.txt', positions=23)
'say'
>>> acrostic('in_memoriam.txt', positions=[4, 7, 12])
'euyoyompikutmnverheye'
>>> acrostic('maude.txt', positions=[1, 2])
'PeCuLiArAcRoStIc'