Just stumbled upon changing a Python list **in place** with list comprehension:
somelist[:] = [elem for elem in somelist if myPredicate(elem)]
Note the peculiar left-hand side of the assignment. Nice.😀
Just stumbled upon changing a Python list **in place** with list comprehension:
somelist[:] = [elem for elem in somelist if myPredicate(elem)]
Note the peculiar left-hand side of the assignment. Nice.😀
I think comprehensions just clicked in my brain at last! 😂 It took reading the wiki page oddly enough. '...is a syntactic construct available in some languages for *creating* a list...'
Its that word *creating* I think that has made it click, and the fact that the underlined green part does the same as '.append'! 💪
Now I am wondering does it work with '.extend' though? 🤔 I guess not because you are looping thru iterables.
My new Post is out! Python: List Comprehensions
{ by @[email protected] } from @[email protected]
#python #listcomprehension https://tongere.hashnode.dev/python-list-comprehensions
This principle is old news in #ClojureScript (and any functional language, true). #listcomprehension
---
RT @VladPasca5
JavaScript tip💡
Stop using "forEach" or "for" loops to loop through an array's items
Instead, start using "map" like in this example
👇