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

    The other answers explain it well but I just wanted to add a bit more about which conditional expression to use in a list comprehension. As the docs state, list comprehensions are used to …

  2. 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?

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

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

  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 - Appending item to lists within a list comprehension

    46 list.append mutates the list itself and returns None. List comprehensions are for storing the result, which isn't what you want in this case if you want to just change the original lists.

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

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

    24 To use the else in list comprehensions in python programming you can try out the below snippet. This would resolve your problem, the snippet is tested on python 2.7 and python 3.5.

  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, 3 months ago Viewed 49k times

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