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]
List comprehension is awesome!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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:
in Python, you would use a list comprehension
You can also transform all the elements in a list (similar to a map in JavaScript):
List comprehension is awesome!