About 85,700 results
Open links in new tab
  1. python - What does "list comprehension" and similar mean? How …

    I've searched and it seems this is called a list comprehension and similarly there seem to be set/dict comprehensions and generator expressions. But how does it work?

  2. python - How can I use list comprehensions to process a nested …

    Here is how you would do this with a nested list comprehension: [[float(y) for y in x] for x in l] This would give you a list of lists, similar to what you started with except with floats instead of …

  3. python - Create a dictionary with comprehension - Stack Overflow

    Create a dictionary with list comprehension in Python I like the Python list comprehension syntax. Can it be used to create dictionaries too? For example, by iterating over pairs of keys and …

  4. python - Are list-comprehensions and functional functions faster …

    Mar 1, 2014 · List comprehensions aren't magic that is inherently faster than a good old loop. As for functional list processing functions: While these are written in C and probably outperform …

  5. python - List comprehension list of lists - Stack Overflow

    Feb 2, 2014 · I have a list of lists, and would like to use list comprehension to apply a function to each element in the list of lists, but when I do this, I end up with one long list rather than my list …

  6. python - if else in a list comprehension - Stack Overflow

    Feb 2, 2013 · python list list-comprehension if-statement edited Mar 28, 2023 at 3:21 Dan D. 75k 15 111 129

  7. Python Asynchronous Comprehensions - how do they work?

    Feb 20, 2017 · Again, to re-iterate, all this already was added in Python 3.5 (see PEP 492), all that is new in Python 3.6 is that you can use such a loop in a list comprehension too. And in …

  8. Is it possible to use 'else' in a list comprehension? [duplicate]

    The syntax a if b else c is a ternary operator in Python that evaluates to a if the condition b is true - otherwise, it evaluates to c. It can be used in comprehension statements: >>> [a if a else 2 …

  9. Multiple IF conditions in a python list comprehension

    Apr 23, 2012 · Multiple IF conditions in a python list comprehension [duplicate] Asked 13 years, 6 months ago Modified 4 years, 2 months ago Viewed 49k times

  10. python - elif in list comprehension conditionals - Stack Overflow

    How can we represent the elif logic in a list comprehension? Up until now, I have only used if and else in list comprehension, as in if/else in a list comprehension.