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

    Because you write the regular for loop using valid python syntax.

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

    I'm not sure if I need a lambda, or something else. But still, I need the following: I have an array = [1,2,3,4,5]. I need to put this array, for instance, into another array. But write it all in one line. …

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

    Sep 15, 2015 · 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 the …

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

  5. 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: if count == N: count = 0 else: count = N + 1 In Objective-C, I wo...

  6. python - Print in one line dynamically - Stack Overflow

    Jul 15, 2010 · I would like to make several statements that give standard output without seeing newlines in between statements. Specifically, suppose I have: for item in range(1,100): print …

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

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

    Dec 31, 2014 · Thanks, I'm a newbie to python, and I've been trying to find the name to this feature.

  9. Python: for loop - print on the same line - Stack Overflow

    I have a question about printing on the same line using for loop in Python 3. I searched for the answer but I couldn't find any relevant. So, I have something like this: def function(s): re...

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

    Dec 30, 2019 · The way to write for loop in a single line, mostly used in Data Science Project, You can use this way, as we have six labeled fake news LIAR: Labels: ['barely-true' 'false' 'half …