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.

How can I get around declaring an unused variable in a for loop?

If I have a list comprehension (for example) like this: ['' for x in myList] Effectively making a new list …

python list-comprehension
python list comprehension to produce two values in one iteration

I want to generate a list in python as follows - [1, 1, 2, 4, 3, 9, 4, 16, 5, 25 .....] You would have figured out, it is nothing but …

python list list-comprehension
List comprehension: Returning two (or more) items for each item

Is it possible to return 2 (or more) items for each item in a list comprehension? What I want (example): [f(…

python list-comprehension
How to set local variable in list comprehension?

I have a method that takes a list and returns an object: # input a list, returns an object def map_…

python list-comprehension
How to count the number of occurrences of `None` in a list?

I'm trying to count things that are not None, but I want False and numeric zeros to be accepted too. …

python boolean list-comprehension nonetype
List Comprehension: why is this a syntax error?

Why is print(x) here not valid (SyntaxError) in the following list-comprehension? my_list=[1,2,3] [print(my_item) for my_item …

python list-comprehension python-2.6
Pythonic Style for Multiline List Comprehension

Possible Duplicate: Line continuation for list comprehensions or generator expressions in python What is the the most pythonic way to …

python coding-style list-comprehension
Why is a list comprehension so much faster than appending to a list?

I was wondering why list comprehension is so much faster than appending to a list. I thought the difference is …

python list python-2.7 python-3.x list-comprehension
An elegant way to get hashtags out of a string in Python?

I'm looking for a clean way to get a set (list, array, whatever) of words starting with # inside a given …

python string list-comprehension hashtag
Make Javascript do List Comprehension

What is the cleanest way to make Javascript do something like Python's list comprehension? In Python if I have a …

javascript jquery python list-comprehension