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.

Appending item to lists within a list comprehension

I have a list, let's say, a = [[1,2],[3,4],[5,6]] I want to add the string 'a' to each item in the list …

python list append list-comprehension
python list comprehensions; compressing a list of lists?

guys. I'm trying to find the most elegant solution to a problem and wondered if python has anything built-in for …

functional-programming python list-comprehension
Picking out items from a python list which have specific indexes

I'm sure there's a nice way to do this in Python, but I'm pretty new to the language, so forgive …

python list list-comprehension
Flattening a list of NumPy arrays?

It appears that I have data in the format of a list of NumPy arrays (type() = np.ndarray): [array([[ 0.00353654]]), array([[ 0.00353654]]), …

python arrays numpy list-comprehension
call list of function using list comprehension

can I call a list of functions and use list comprehension? def func1():return 1 def func2():return 2 def func3():return 3 …

python list function list-comprehension
How can I do assignments in a list comprehension?

I want to use the assignment operator in a list comprehension. How can I do that? The following code is …

python list-comprehension
Add an element in each dictionary of a list (list comprehension)

I have a list of dictionaries, and want to add a key for each element of this list. I tried: …

python python-3.x list-comprehension
Advanced Nested List Comprehension Syntax

I was playing around with list comprehensions to get a better understanding of them and I ran into some unexpected …

python syntax scope list-comprehension
How to return a subset of a list that matches a condition?

Let's say I have a list of ints: listOfNumbers = range(100) And I want to return a list of the elements …

python list list-comprehension
List comprehension in Ruby

To do the equivalent of Python list comprehensions, I'm doing the following: some_array.select{|x| x % 2 == 0 }.collect{|x| x * 3} …

ruby list-comprehension