About 527,000 results
Open links in new tab
  1. Comprehensions in Python - GeeksforGeeks

    Feb 22, 2025 · Comprehensions in Python provide a concise and efficient way to create new sequences from existing ones. They enhance code readability and reduce the need for lengthy …

  2. List Comprehension in Python - GeeksforGeeks

    Mar 21, 2025 · List comprehension is a way to create lists using a concise syntax. It allows us to generate a new list by applying an expression to each item in an existing iterable (such as a …

  3. Python list comprehension for loops - Stack Overflow

    List comprehension supports more than one for statement. It will evaluate the items in all of the objects sequentially and will loop over the shorter objects if one object is longer than the rest. …

  4. When to Use a List Comprehension in Python

    List comprehensions in Python provide a concise way to create lists by embedding a loop and optional conditional logic in a single line. You use a list comprehension to transform and filter …

  5. Comprehensions in Python—Write Shorter For Loops

    Turn your for loops into one-liners by using comprehensions. Python supports four comprehensions for the common data structures: List Comprehension; Dictionary …

  6. Python List Comprehension (With Examples) - Programiz

    List comprehension makes the code cleaner and more concise than for loop. Let's write a program to print the square of each list element using both for loop and list comprehension. for …

  7. python - if/else in a list comprehension - Stack Overflow

    How do I convert the following for -loop containing an if / else into a list comprehension? results.append(f(x) if x is not None else '') It should yield '' if x is None, and otherwise f(x). I …

  8. For Loop vs. List Comprehension - Sebastian Witowski

    Sep 17, 2020 · Many simple "for loops" in Python can be replaced with list comprehensions. You can often hear that list comprehension is "more Pythonic" (almost as if there was a scale for …

  9. Python - List Comprehension - W3Schools

    List comprehension offers a shorter syntax when you want to create a new list based on the values of an existing list. Example: Based on a list of fruits, you want a new list, containing …

  10. Python List Comprehension: single, multiple, nested, & more

    Using list comprehension instead of a for loop, we've managed to pack four lines of code into one clean statement. In this article, we'll first look at the different ways to use list comprehensions …

Refresh