Become a more efficient Python programmer
During a recent project, I was focused on putting into practice many Python commands that would make my coding much more efficient. I classify these as my “must-haves” for programming efficiently, which include standard Python commands for working with lists, functions and even basic print statements. What other commands would you include in your list of must-haves?
map functions
Python’s map command allows programmers to apply a function to all items of an iterable, such as a list or tuple. In this example, each element in the list is cubed. Don’t forget to turn the result into a list, as can be seen by the command list(map(…)), otherwise your result will be a mapped object.
For advanced users, lambda functions can also be used in place of defining a function. You will see an example of this below.
Anonymous functions are easy!
The lambda keyword is powerful in Python, allowing you to write standard functions that would normally return only one line. Remember that lambda’s are often called anonymous functions. The lamba function below can be read as “a function without a name…