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.

Python's most efficient way to choose longest string in list?

I have a list of variable length and am trying to find a way to test if the list item …

python list list-comprehension
How to unzip a list of tuples into individual lists?

Possible Duplicate: A Transpose/Unzip Function in Python I have a list of tuples, where I want to unzip this …

python list tuples list-comprehension
Double Iteration in List Comprehension

In Python you can have multiple iterators in a list comprehension, like [(x,y) for x in a for y …

python list-comprehension
Flattening a shallow list in Python

Is there a simple way to flatten a list of iterables with a list comprehension, or failing that, what would …

python list-comprehension
List comprehension with if statement

I want to compare 2 iterables and print the items which appear in both iterables. >>> a = ('q', 'r') &…

python if-statement list-comprehension
List comprehension on a nested list?

I have this nested list: l = [['40', '20', '10', '30'], ['20', '20', '20', …

python list nested list-comprehension
Python for and if on one line

I have a issue with python. I make a simple list: >>> my_list = ["one","two","three"] I …

python python-2.7 for-loop if-statement list-comprehension
Generator Expressions vs. List Comprehension

When should you use generator expressions and when should you use list comprehensions in Python? # Generator expression (x*2 for x …

python list-comprehension generator
Is it possible to use 'else' in a list comprehension?

Here is the code I was trying to turn into a list comprehension: table = '' for index in xrange(256): if …

python list-comprehension
Why is there no tuple comprehension in Python?

As we all know, there's list comprehension, like [i for i in [1, 2, 3, 4]] and there is dictionary comprehension, like {i:j …

python tuples list-comprehension dictionary-comprehension set-comprehension