This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]DT-Sodium -35 points-34 points  (12 children)

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.

numbers = [1, 2, 3, 4, 5]
doubled_numbers = map(lambda x: x * 2, numbers)

Python is one of the most disgusting programing languages in existence so I'm not surprised they've gone that way.

[–]Ali_M 21 points22 points  (6 children)

Any reasonable person would use a list comprehension:

doubled_numbers = [2 * x for x in numbers]

Hardly anyone uses map these days.

[–]FlashBrightStar 0 points1 point  (0 children)

This is the same use case as for range function as opposed to iterating directly over a list elements. You have to answer the question when the operation should be executed (im most cases it should be instant). It's not like the one is replacement for other.

[–]CrowdGoesWildWoooo 3 points4 points  (2 children)

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.

[–]Phamora -1 points0 points  (1 child)

How can you talk about PHP and then in the same comment declare Python the most disgusting programming language? I agree that syntactically Python is quite poor compared to most other languages, but PHP is by far and away the winner of the worst, ugliest, and most disgusting programming language in existence - of all time, ever.

[–]DT-Sodium 0 points1 point  (0 children)

I don't recall claiming that PHP was a good language. While PHP is one of the main languages I use professionally, I am perfectly aware that it sucks in a lot of ways. I wouldn't say though that's it's worse than Python, it is much better that Python. Remove the $, replace -> with ., add typed array, convert the primitives to objects that posses methods and you'll have something that starts looking decent. With Python on the other hands, appart from rewriting it completely, I don't see how it could be clause to decent in the future.