DEV Community

Discussion on: What's a useful programming language feature or concept that a lot of languages don't have?

Collapse
 
aspittel profile image
Ali Spittel • Edited

Python's list comprehensions! The syntax is super elegant, and they are really performant.

In JavaScript, to filter values, you would do something like this:

arr.filter(function(i) {
  return i > 0
})

in Python, you would use a list comprehension

li = [i for i in li if i > 0]

You can also transform all the elements in a list (similar to a map in JavaScript):

li = [x * 2 for x in li]
Collapse
 
avalander profile image
Avalander

List comprehension is awesome!