About 50 results
Open links in new tab
  1. python - Understanding the syntax of list comprehensions - Stack …

    Jul 16, 2021 · Python list comprehensions are for loops executed in a list to generate a new list.The reason python list comprehensions are evaluated backward from or right to left is because usually …

  2. 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. 75.1k 15 111 129

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

    Note that this actually uses a different language construct, a conditional expression, which itself is not part of the comprehension syntax, while the if after the for…in is part of list comprehensions and …

  4. How can I use list comprehensions to process a nested list?

    newList = [] for x in l: for y in x: newList.append(float(y)) How can I solve the problem with a nested list comprehension instead? See also: How can I get a flat result from a list comprehension instead of a …

  5. python - List Comprehension: why is this a syntax error ... - Stack ...

    print in python 3 makes it more obvious on how to use it. the square brackets in the list comprehension denotes that the output will actually be a list. L1=['a','ab','abc'] print([item for item in L1]) This should …

  6. python - List comprehension syntax - how to use ... if... else? - Stack ...

    May 7, 2019 · A list comprehension consists of brackets containing an expression followed by a for clause, then zero or more for or if clauses. The result will be a new list resulting from evaluating the …

  7. 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 and values:

  8. python list comprehension with multiple 'if's - Stack Overflow

    We all know python's [f(x) for x in y if g(x)] syntax. However the AST representation of list comprehension has room for more than one 'if' expression: comprehension = (expr target, expr iter, ...

  9. python - Nested list comprehensions - Stack Overflow

    Aug 13, 2012 · python list syntax list-comprehension edited May 31, 2022 at 15:35 LeopardShark 4,496 4 21 37

  10. python - Lambda function in list comprehensions - Stack Overflow

    This question touches a very stinking part of the "famous" and "obvious" Python syntax - what takes precedence, the lambda, or the for of list comprehension. I don't think the purpose of the OP was to …