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.

if/else in a list comprehension

How can I do the following in Python? row = [unicode(x.strip()) for x in row if x is not …

python list-comprehension
Create a dictionary with list comprehension

I like the Python list comprehension syntax. Can it be used to create dictionaries too? For example, by iterating over …

python dictionary list-comprehension dictionary-comprehension
if else in a list comprehension

I have a list l: l = [22, 13, 45, 50, 98, 69, 43, 44, 1] For numbers above 45 inclusive, I would like to add 1; and for numbers less than …

python list list-comprehension if-statement
Create list of single item repeated N times

I want to create a series of lists, all of varying lengths. Each list will contain the same element e, …

python list-comprehension multiplication replicate
Pythonic way to print list items

I would like to know if there is a better way to print all objects in a Python list than …

python list printing list-comprehension
Creating a dictionary from a csv file?

I am trying to create a dictionary from a csv file. The first column of the csv file contains unique …

python csv dictionary list-comprehension
Python Dictionary Comprehension

Is it possible to create a dictionary comprehension in Python (for the keys)? Without list comprehensions, you can use something …

python dictionary list-comprehension
One-line list comprehension: if-else variants

It's more about python list comprehension syntax. I've got a list comprehension that produces list of odd numbers of a …

python list-comprehension ternary-operator conditional-operator
Python using enumerate inside list comprehension

Lets suppose I have a list like this: mylist = ["a","b","c","d"] To get the values printed along with …

python list iteration list-comprehension
List comprehension vs map

Is there a reason to prefer using map() over list comprehension or vice versa? Is either of them generally more …

python list-comprehension map-function