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.

Build Dictionary in Python Loop - List and Dictionary Comprehensions

I'm playing with some loops in python. I am quite familiar with using the "for" loop: for x in y: …

python for-loop list-comprehension dictionary-comprehension
In Python list comprehension is it possible to access the item index?

Consider the following Python code with which I add in a new list2 all the items with indices from 1 to 3 …

python list list-comprehension
Nested For Loops Using List Comprehension

If I had two strings, 'abc' and 'def', I could get all combinations of them using two for loops: for …

python for-loop list-comprehension
How do I get a list of indices of non zero elements in a list?

I have a list that will always contain only ones and zeroes. I need to get a list of the …

list python list-comprehension
List comprehension for loops Python

I use a lot of N dimensional arrays and it gets a pain to have to write such indented code …

python inline list-comprehension
How to handle exceptions in a list comprehensions?

I have some a list comprehension in Python in which each iteration can throw an exception. For instance, if I …

python exception list-comprehension
Counting positive integer elements in a list with Python list comprehensions

I have a list of integers and I need to count how many of them are > 0. I'm currently doing …

python list sum integer list-comprehension
python list comprehension with multiple 'if's

We all know python's [f(x) for x in y if g(x)] syntax. However the AST representation of list …

python if-statement list-comprehension
How do I convert a tuple of tuples to a one-dimensional list using list comprehension?

I have a tuple of tuples - for example: tupleOfTuples = ((1, 2), (3, 4), (5,)) I want to convert this into a flat, one-dimensional list …

python tuples list-comprehension iterable-unpacking
Fastest way to get the last element of a list in Haskell

What is the fastest way to get the last element of a list in Haskell. Also in next iteration, I …

haskell list-comprehension