About 177,000 results
Open links in new tab
  1. python - if/else in a list comprehension - Stack Overflow

    List comprehension where an if statement follows a for statement (case (2) above) is similar to the math notation to define a subset from a given set, so [x for x in iterable if m<x<n] is similar to …

  2. python - What does "list comprehension" and similar mean? How …

    I've seen a lot of confusion lately (on other SO questions and from coworkers) about how list comprehensions work. A wee bit of math education can help with why the syntax is like this, …

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

    How can I use list comprehensions to process a nested list? Asked 12 years, 4 months ago Modified 1 month ago Viewed 266k times

  4. 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 …

  5. 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

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

    54 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 …

  7. python - List comprehension with if statement - Stack Overflow

    Mar 18, 2013 · python if-statement list-comprehension edited Nov 29, 2017 at 20:50 Martijn Pieters 1.1m 326 4.2k 3.4k

  8. 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 …

  9. python - How to set local variable in list comprehension ... - Stack ...

    Oct 31, 2014 · 97 Starting in Python 3.8, and the introduction of assignment expressions (PEP 572) (:= operator), it's possible to use a local variable within a list comprehension in order to …

  10. Python list function or list comprehension - Stack Overflow

    Aug 15, 2018 · 2 In first case you use list comprehension syntax. It's the fastest way to map some function on list in python. In second case you create a generator