Panini football stickers are pure nostalgia! They are produced by the Italian-based Panini company that is specialized in the distribution of self-adhesive sticker collections. Ever since its foundation, the company produces sticker collections about movies and computer games, but the football collections have always been by far the most popular ones.
Every Panini booklet contains hundreds of empty placeholders that need to be covered by different stickers. The stickers are numbered sequentially so that their position in the booklet can be found easily. Four or five randomly selected stickers are bundled together in a sealed container. This way, collectors do not know in advance which stickers they purchase. As a result, it becomes extremely hard to complete the entire collection, creating a collective rage whereby collectors mutually exchange their duplicate stickers.
Because collectors need to be able to quickly lookup what stickers that already have in their possession while exchanging stickers, they use a shorthand notation to describe their collection. Say, for example, that a collector has the following stickers in his possession
1, 3, 4, 5, 6, 7, 9, 10, 11, 17, 19, 20
then he will describe his collection using the following shorthand notation.
1, 3-7, 9-11, 17, 19-20
This notation abbreviates each sequence of successive integers as the first and the last integer in the sequence, separated from each other using a dash (-). Individual integers and integer sequences are listed in increasing order, separated from each other using a comma (,) and a space.
Define a class Panini that can be used to represent collections of Panini stickers. Each sticker occurs at most once in the collection. The class must support at least the following methods:
An initialization method that either takes an integer (int; that represents the number of a single sticker) or a list, a tuple or a set of integers (int; that represent the numbers of all stickers in the collection). In case the argument passed to the initialization method does not meet this condition, the method must raise an AssertionError with the message invalid stickers. The list or tuple passed to the method must not necessarily contain the integers in increasing order. In case the list or tuple passed to the method contains duplicate integers, these stickers must be included in the collection just once.
A method that allows two add to collections of stickers using the + operator. In doing so, the original collections must remain unchanged, with the addition resulting in a new collection (Panini) that contains the stickers that are in either of the two initial collections. This new collection may not contain duplicate stickers.
A method that allows to generate a new collection that contains the stickers that are in one collection but not in another collection using the - operator. In doing so, the original collections must remain unchanged, but the subtraction should result in a new collection (Panini) that contains all stickers from the left-hand collection that do not occur in the right-hand collection.
In addition, it should also be possible to use the built-in functions repr and str to generate a string representation for each object of the class Panini. The string returned by these functions must contain the shorthand notation of the collection of stickers represented by the object. Both function should thus return the same string representation of an object.
>>> collection1 = Panini([1, 3, 4, 5, 6, 7, 9, 10, 11, 17, 19, 20])
>>> collection1
1, 3-7, 9-11, 17, 19-20
>>> print(collection1)
1, 3-7, 9-11, 17, 19-20
>>> collection2 = Panini(8)
>>> collection2
8
>>> print(collection2)
8
>>> collection3 = collection1 + collection2
>>> isinstance(collection3, Panini)
True
>>> collection3
1, 3-11, 17, 19-20
>>> collection4 = collection1 - Panini((5, 8))
>>> isinstance(collection4, Panini)
True
>>> collection4
1, 3-4, 6-7, 9-11, 17, 19-20
>>> collection1 - Panini({1, 2, 3, 4}) + Panini(list(range(10, 19)))
5-7, 9-20
>>> Panini('spam')
Traceback (most recent call last):
AssertionError: invalid stickers
>>> Panini([1, 2, 3.14])
Traceback (most recent call last):
AssertionError: invalid stickers