About 50 results
Open links in new tab
  1. 'for' loop in one line in Python - Stack Overflow

    For the Step 3 we just need to apply pow(x, 3) (or x ** 3) and we can fit everything in a single line using list comprehension, then we can fit that in a lambda function or inside the return …

  2. lambda - Python one-line "for" expression - Stack Overflow

    Python one-line "for" expression [duplicate] Asked 16 years, 4 months ago Modified 7 years, 9 months ago Viewed 435k times

  3. python - Single Line Nested For Loops - Stack Overflow

    Feb 25, 2015 · The best source of information is the official Python tutorial on list comprehensions. List comprehensions are nearly the same as for loops (certainly any list …

  4. Python for and if on one line - Stack Overflow

    Sep 15, 2015 · 24 In list comprehension the loop variable i becomes global. After the iteration in the for loop it is a reference to the last element in your list. If you want all matches then assign …

  5. python - 'While' loop one-liner - Stack Overflow

    Feb 4, 2023 · When using a compound statement in python (statements that need a suite, an indented block), and that block contains only simple statements, you can remove the newline, …

  6. How to write a for loop and multiple if statements in one line?

    Dec 30, 2019 · How to write a for loop and multiple if statements in one line? Asked 6 years, 1 month ago Modified 4 years, 8 months ago Viewed 7k times

  7. python - Putting a simple if-then-else statement on one line

    How do I write an if - then - else statement in Python so that it fits on one line? For example, I want a one line version of:

  8. python - Assignment to an item of a list in single line for loop ...

    Dec 22, 2017 · 1 I want to make an assignment to an item of a list in a single line for loop. First i have a list, where each list items are dictionary object. Then, i do for loop over each item of the …

  9. python - Single line for loop over iterator with an "if" filter ...

    3 This is a design philosophy of python. If it takes you too many words to put it on one line, it should be broken into a few lines to help the person who comes after you. List and generator …

  10. python - Use one line of code to print a for loop - Stack Overflow

    Feb 18, 2016 · I have a list of strings stored in results that I want to print one at a time to look like this: String 1 String 2 String 3 etc. Right now, I have this, which works fine: for line in results: ...