What three bands are hidden in this sequence of words?
PINUP, BEIRUT, TELEVISED, JAPANNED, TRIBALISM
The three bands are OASIS, QUEEN and NIRVANA. You get the band OASIS by taking the previous letter in the alphabet for the first letter of each word. You get the band QUEEN by taking the next letter in the alphabet for the last letter of each word. You get the band NIRVANA by taking the middle letter(s) of each word. Words with an odd number of letters have one middle letter and words with an even number of letters have two middle letters.
We consider words that consist of one or more uppercase letters and represent them as strings (str).
A selector is a function that takes a word $$w$$ and returns a word. Your task is to define the following selectors:
A selector predecessor that returns the previous letter in the alphabet of the first letter of $$w$$, where we assume that the letter A is preceded by the letter Z.
A selector successor that returns the next letter in the alphabet of the last letter of $$w$$, where we assume that the letter Z is followed by the letter A.
A selector middle that returns the middle letter(s) of $$w$$. Words with an odd number of letters have one middle letter and words with an even number of letters have two middle letters.
A selector sumaround that returns an uppercase letter that is determined in the following way. Each letter in the alphabet gets a value according to its position in the alphabet: A=0, B=1, C=2, …, Z=25. We add up the values of all letters in $$w$$ and compute the remainder after division by 26. The letter whose value corresponds to this remainder is the letter returned by the selector.
Now also define a function hidden that takes two arguments: i) a sequence (list or tuple) of words and ii) a selector $$s$$. The function must return the word obtained by concatenating all letters that selector $$s$$ returns for each of the consecutive words in the given sequence.
>>> predecessor('PINUP')
'O'
>>> predecessor('BEIRUT')
'A'
>>> predecessor('TELEVISED')
'S'
>>> successor('PINUP')
'Q'
>>> successor('BEIRUT')
'U'
>>> successor('TELEVISED')
'E'
>>> middle('PINUP')
'N'
>>> middle('BEIRUT')
'IR'
>>> middle('TELEVISED')
'V'
>>> sumaround('PYTHONS')
'G'
>>> sumaround('STANCHED')
'O'
>>> sumaround('ALGA')
'R'
>>> centroid('PYTHONS')
'P'
>>> centroid('STANCHED')
'E'
>>> centroid('ALGA')
'A'
>>> hidden(['PINUP', 'BEIRUT', 'TELEVISED', 'JAPANNED', 'TRIBALISM'], predecessor)
'OASIS'
>>> hidden(['PINUP', 'BEIRUT', 'TELEVISED', 'JAPANNED', 'TRIBALISM'], successor)
'QUEEN'
>>> hidden(['PINUP', 'BEIRUT', 'TELEVISED', 'JAPANNED', 'TRIBALISM'], middle)
'NIRVANA'
>>> hidden(('PYTHONS', 'STANCHED', 'ALGA', 'REBUS', 'NELLY', 'SUBJECTIVELY', 'ARABIA', 'ARMAMENT'), sumaround)
'GORILLAZ'
>>> hidden(('PYTHONS', 'STANCHED', 'ALGA', 'REBUS', 'NELLY', 'SUBJECTIVELY', 'ARABIA', 'ARMAMENT'), centroid)
'PEARLJAM'