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.😀

#python #listcomprehension #listmutation

Here's a one-liner that generates a Fibonacci sequence up to the 10th term using list comprehension: #python #listcomprehension
Python’s Map() and List Comprehension: Tips and Best Practices #python #map #listcomprehension
https://www.techbeamers.com/python-map-list-comprehension-best-practices/
Python's Map() and List Comprehension: Tips and Best Practices

Explore Python's map() and list comprehension best practices for efficient, concise coding with practical examples and tips.

TechBeamers

@jzik
I read everywhere that #python code should be clean , simple and readable and yet list comprehension obscures deeply what the code does.

What am I missing? 🤷‍♀️

#ListComprehension #python

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.

#python #listcomprehension

Python: List Comprehensions

Comprehensions are an extremely powerful part of Python. But what are they and how can they help me? As you code, you'll notice that certain patterns happen over and over again. Looping through some iterable and create a list is extremely common. Pyt...

Tongere

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

👇

https://twitter.com/VladPasca5/status/1436735335539658753

Vlad Pasca on Twitter

“JavaScript tip💡 Stop using "forEach" or "for" loops to loop through an array's items Instead, start using "map" like in this example 👇”

Twitter