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

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

  8. python - Single line for-loop to build a dictionary? - Stack Overflow

    Dec 31, 2014 · I'm constructing a dictionary (which I'll later make into a JSON string). I construct it like this: data = {} for smallItem in bigList: data[smallItem] = smallItem How can I make that for …

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

  10. python - How can I print in one single line after using a for loop ...

    Jul 18, 2022 · How can I print in one single line after using a for loop Asked 3 years, 7 months ago Modified 3 years, 7 months ago Viewed 977 times