We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

Fabien • 2 years ago

Nice job, the examples are well chosen.

I would suggest that args2 should be renamed kwargs for consistency in "unpacking arguments":


print("Call function repeat using a dictionary of keyword arguments:")
kwargs = {'count': 4, 'name': 'cats'}
repeat(**kwargs)
[CG]Maxime • 2 years ago

Thank you, I've updated the playground.

jolindien • 2 years ago

I didn't know defaultdict ... really useful !
Thanks

Federico Ponzi • 2 years ago

Thanks, this was very interesting!

MathJason • 2 years ago

This was really great. I didn't know about the one line `tree()` hack, or the decorators `@contextmanager` or `@lru_cache`. Also, with the `@contextmanager` example, it may be more clear to add comments like this. (However, I understood it just fine, so I don't know if I am being to nitpicky.)

@contextmanager
def colored_output(color):
print("\033[%sm" % color, end="") # lines before the yield associated with __enter__ method
yield
print("\033[0m", end="") # lines after the yield associated with __exit__ method

[CG]Maxime • 2 years ago

You're right, a comment can be helpful. I've added your suggestion.

chossette • 2 years ago

Tx, many thing I did not known

Katie Clark • 11 months ago

Thanks for these demos! Really handy stuff, quite a few new things for me!

maklai • 1 year ago

Unpacking arguments example - it is more precise if args(line 6) is a tuple instead of a list.

dhmoclex • 2 years ago

Very very nice! :D
Thank you very much for your course!

I was especially amazed by the defaultdict tree and the cache decorator !

Thanks!