Comparing Javascript with Python map and filter functions
In previous tutorials, we showed you how to use the map and filter functions in both Javascript and Python. Lets compare the two popular languages.
First there is the naming conventions.
Javascript variables tend to be camelCase and Python is snake_case.
Javascript declare variables with let, const, or var. Python don’t declare, just use.
Javascript statement tend to still end with semicolons (although they can be omitted). Python has no terminal character for statements.
In Javascript, the map method is a method of the array. You call it from the array. This is why you don’t need to pass the array to map into the map function. In Python, the map function is a standard function in core. You just use it (no even need to import). Therefore you have to pass it the map function and the array to be mapped. In both Javascript and Python, the first parameter of map, is the map function.
Similarly for filter method.
Both map and filter can take anonymous inline functions. In Javascript, these are arrow functions. In Python, these are called lambdas.