[0] http://www.wikihow.com/Make-Phirni-%28a-Rice-and-Milk-Dish%2...
Python idioms I wish I'd learned earlier
171–174 of 174 posts
Re: Python idioms I wish I'd learned earlier
#172This is something I do instead of writing a long if-else: opt = {0: do_a, 1: do_b, 3: do_b, 4: do_c} opt[option]()
Edit: Looked it up, dispatch table is in Wikipedia:
Re: Python idioms I wish I'd learned earlier
#173Earlier quoted context omitted.
> 1. Am I the only one that really loves that `print` is a statement and not a function? Call me lazy, but I don't mind not having to type additional parentheses. If you think the parentheses are bad, why wouldn't you prefer a language like Ruby where you can omit them generally? Leaving them out for just one special construct seems so insufficient as a cure.
In general, Ruby's syntax (or rather, semantics) is ambiguous (you don't know if a statement without parentheses is calling a function or just accessing a value). I prefer unambiguous syntax. However, Python's `print` statement is (1) well-known, (2) very useful (for prototyping, debugging, in REPL), and (3) shouldn't in general be present in production code (logging should be used instead). Therefore, omitting paren…
In [9]: %autocall Automatic calling is: Smart
In [10]: def foo(a, b): return a + b ....:
In [11]: foo 3, 4 -------> foo(3, 4) Out[11]: 7
`
Re: Python idioms I wish I'd learned earlier
#174If you were underwhelmed by this blog post have a look at: Transforming code into Beautiful, Idiomatic Python by Raymond Hettinger at PyCon 2013 https://speakerdeck.com/pyconslides/transforming-code-into-b... and https://www.youtube.com/watch?v=OSGv2VnC0go&noredirect=1 Topics include: 'looping' with iterators to avoid creating new lists, dictionaries, named tuples and more
Sorry for the offtopic but why did you add `&noredirect=1` to the end of that youtube url?