As far as I know, comprehensions in Python only work with lists, dictionaries, tuples and sets. There is nothing on comprehension in the Python data model.
The syntax for tuples is quite interesting
>>> tuple(i for i in range(3))
(0, 1, 2)
Following the same pattern, I'd like to write a comprehension for my custom class.
>>> MySequence(i for i in range(3))
MySequence(0, 1, 2)
>>> MyMapping{str(i): i for i in range(3)}
MyMapping({'0': 0, '1': 1, '2': 2})
How can I achieve that?