Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
nExT stage 4 solution in Creative category for I Love Python! by CDG.Axel
from itertools import chain, cycle, islice, repeat
from io import StringIO
def i_love_python():
"""
some rare function used
- io.StringIO
- cycle, islice, repeat, chain from itertools
last functions of list and dict:
- popitem, setdefault, keys
- reverse
"""
exceptions = [AssertionError, BufferError, BytesWarning, ImportError, KeyError, LookupError,
MemoryError, OverflowError, RecursionError, ReferenceError, UnicodeDecodeError,
UnicodeEncodeError, ZeroDivisionError]
out = StringIO()
d = {5: 'Yep', 3: '!!!'}
rep, _ = d.popitem()
d.setdefault(4, 'Nop')
l = [*d.keys()]
l.reverse()
it = islice(cycle(chain('hate', repeat('love', rep))), * l)
print(next(it), file=out, end='')
text = out.getvalue()
out.close()
if all(issubclass(e, BaseException) for e in exceptions):
return f'I {text} Python!'
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert i_love_python() == "I love Python!"
Dec. 13, 2021