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 list comprehension vs .NET LINQ

The following simple LINQ code string[] words = { "hello", "wonderful", "linq", "beautiful", "world" }; // Get only short words var shortWords = from word …

c# python linq list-comprehension
List comprehension, check if item is unique

I am trying to write a list comprehension statement that will only add an item if it's not currently contained …

python list dictionary list-comprehension
In Python, is it better to use list comprehensions or for-each loops?

Which of the following is better to use and why? Method 1: for k, v in os.environ.items(): print "%s=%…

python coding-style foreach list-comprehension
List comprehension in Swift

The language guide has revealed no trace of list comprehension. What's the neatest way of accomplishing this in Swift? I'm …

swift list-comprehension
Are for-loops in pandas really bad? When should I care?

Are for loops really "bad"? If not, in what situation(s) would they be better than using a more conventional "…

python pandas iteration vectorization list-comprehension
Running average in Python

Is there a pythonic way to build up a list that contains a running average of some function? After reading …

python list-comprehension moving-average
List comprehension rebinds names even after scope of comprehension. Is this right?

Comprehensions are having some unexpected interactions with scoping. Is this the expected behavior? I've got a method: def leave_room(…

python binding list-comprehension
Split a list into nested lists on a value

Say I have a list like so: [1, 4, None, 6, 9, None, 3, 9, 4] I decide to split this into nested lists on None, to …

python list-comprehension nested-lists
Unpacking tuples in a python list comprehension (cannot use the *-operator)

I am trying to create a list based on another list, with the same values repeated 3 times consecutively. At the …

python tuples list-comprehension iterable-unpacking
yield in list comprehensions and generator expressions

The following behaviour seems rather counterintuitive to me (Python 3.4): >>> [(yield i) for i in range(3)] <generator …

python generator list-comprehension yield generator-expression