Post

@PythonPr map is cool, but my eyes prefer the pythonic way
squares = [x**2 for x in numbers]
English

@PythonPr Python programmers really hate for and any kind of loops, don't they?
English

@PythonPr Don’t you feel disgusting for the second implementation?😂
English

Nice use of map().
Another common Pythonic option here is list comprehension:
squares = [n ** 2 for n in nums]
I ran a small timeit comparison:
for loop + append → 1.1768
map(...) → 1.0982
list comprehension → 0.7580
So for this simple transformation, I’d probably choose the list comprehension.
#Python #PythonCode #Coding #Programming #CodeNewbie #100DaysOfCode
English







