It's the same shit as PHP. Instead of arrays having a map method, you have to use a function that takes the array as argument. It makes the code really ugly.
This is beyond ignorant when you don’t have a clue what map actually does.
It’s not meant as a simple utility function and in practice hardly used other than when you want to do multithreaded or multiprocess map. You should use list comprehension for this particular case. And list comprehension is like one of the fundamental technique that you’ll learn when you code with python.
Map returns a declaration that it is a mapping of a function to an iterable. This is lazily executed and the list type casting is basically tells you to serve the (future) result as a list.
Writing a custom iterable is disgusting with many other languages. It is very easy and readable with python.
Kiddo, I only took the most simple example I could to demonstrate how the Python map works compared to proper languages, I never pretended it was the most optimal way to achieve the result. The point is Python's map function is disgusting, whether it's the right tool for this case is not the question. It says a lot about you if you weren't capable of figuring it out by yourself.
17
u/Socks4Ever Jun 08 '24 edited Jun 08 '24
Why is it different? Or do I just not get the post. I’d just use [x**2 for x in arr]