Interleave the letters of the words SHOE and COLD and you get the word SCHOOLED.

alternade
SHOE + COLD = SCHOOLED

The same procedure can also be applied to interleave the letters of three words to produce a fourth.

alternade
SIR + ILL + MAY = SIMILARLY

However, interleaving the letters of a series of words is not limited to words having equal length. The general procedure repeatedly takes the next letter of the next word, where the last word is again followed by the first word. If all letters of a given word have been taken, that word is ignored in the remainder of the procedure. The procedure ends if all letters of all words have been taken.

alternade
DEMO + RABAT = DREAMBOAT

Assignment

Define a class Alternade that can be used to interleave the letters of a series of words. The objects of the class Alternade must at least support the following methods:

Preparation

To determine whether a given object has a certain type of specifications, you can of course use the built-in function type(o), that prints the type of specification of the object o. However, it is better to use the built-in function isinstance(o, t). This function prints a Boolean value that indicates whether the object o belongs to type t, or not.

>>> type(3) == int
True
>>> isinstance(3.14, int)
False
>>> isinstance(3.14, float)
True
>>> isinstance([1, 2, 3], list)
True

Example

>>> word1 = Alternade('SHOE')
>>> word1.words
['SHOE']
>>> word1
Alternade('SHOE')
>>> print(word1)
SHOE

>>> words = ['COLD']
>>> word2 = Alternade(words)
>>> word2.words
['COLD']
>>> id(words) != id(word2.words)
True
>>> word2
Alternade('COLD')

>>> word3 = word1 + word2
>>> isinstance(word3, Alternade)
True
>>> word3.words
['SHOE', 'COLD']
>>> word3
Alternade(['SHOE', 'COLD'])
>>> print(word3)
SCHOOLED
>>> word1
Alternade('SHOE')
>>> word2
Alternade('COLD')
		
>>> word4 = Alternade('DEMO') + Alternade('RABAT')
>>> word4
Alternade(['DEMO', 'RABAT'])
>>> print(word4)
DREAMBOAT

>>> word5 = Alternade('SIR') + Alternade('ILL') + Alternade('MAY')
>>> word5.words
['SIR', 'ILL', 'MAY']
>>> word5
Alternade(['SIR', 'ILL', 'MAY'])
>>> print(word5)
SIMILARLY