Top "List-comprehension" questions

A syntactic construct which provides a concise way to create lists in a style similar to the mathematical set-builder notation.

Possible to return two lists from a list comprehension?

Is it possible to return two lists from a list comprehension? Well, this obviously doesn't work, but something like: rr, …

python list-comprehension
convert string to dict using list comprehension

I have came across this problem a few times and can't seem to figure out a simple solution. Say I …

python string dictionary list-comprehension generator-expression
Generate a sequence of Fibonacci number in Scala

def fibSeq(n: Int): List[Int] = { var ret = scala.collection.mutable.ListBuffer[Int](1, 2) while (ret(ret.length - 1) < n) { …

scala sequence list-comprehension fibonacci
Is it possible to add a where clause with list comprehension?

Consider the following list comprehension [ (x,f(x)) for x in iterable if f(x) ] This filters the iterable based …

python python-3.x list-comprehension python-assignment-expression python-3.8
How do I create a list of Python lambdas (in a list comprehension/for loop)?

I want to create a list of lambda objects from a list of constants in Python; for instance: listOfNumbers = [1,2,3,4,5] square = …

python lambda scope closures list-comprehension
List comprehension with condition

I have a simple list. >>> a = [0, 1, 2] I want to make a new list from it using a …

python if-statement list-comprehension generator-expression
List comprehension without [ ] in Python

Joining a list: >>> ''.join([ str(_) for _ in xrange(10) ]) '0123456789' join must take an iterable. Apparently, …

python list-comprehension
Does PHP have an equivalent to Python's list comprehension syntax?

Python has syntactically sweet list comprehensions: S = [x**2 for x in range(10)] print S; [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] In PHP I would need to …

php arrays list-comprehension higher-order-functions language-comparisons
How to remove list of words from a list of strings

Sorry if the question is bit confusing. This is similar to this question I think this the above question is …

python regex list-comprehension stop-words
Recursive list comprehension in Python?

Is it possible to define a recursive list comprehension in Python? Possibly a simplistic example, but something along the lines …

python list-comprehension