About 86,800 results
Open links in new tab
  1. Is there a 'foreach' function in Python 3? - Stack Overflow

    Aug 18, 2013 · The correct answer is "python collections do not have a foreach". In native python we need to resort to the external for _element_ in _collection_ syntax which is not what the OP …

  2. Python foreach equivalent - Stack Overflow

    Oct 31, 2016 · The foreach construct is unfortunately not intrinsic to collections but instead external to them. The result is two-fold: it can not be chained; it requires two lines in idiomatic …

  3. python - How can I access the index value in a 'for' loop? - Stack …

    Notice that the index runs from 0. This kind of indexing is common among modern programming languages including Python and C. If you want your loop to span a part of the list, you can use …

  4. python - loop for inside lambda - Stack Overflow

    To add on to chepner's answer for Python 3.0 you can alternatively do: x = lambda x: list(map(print, x)) Of course this is only if you have the means of using Python > 3 in the …

  5. Python List & for-each access (Find/Replace in built-in list)

    Sep 15, 2011 · When a for-loop executes, it takes the name you give it, and binds it in turn to each object in the iterable while running the loop; when you call a function, it takes the names …

  6. python - Pythonic way to combine for-loop and if-statement

    @KirillTitov Yes python is a fundamentally non-functional language (this is a purely imperative coding - and I agree with this answer's author that it is the way python is set up to be written. …

  7. foreach - In detail, how does the 'for each' loop work in Java?

    The foreach loop, added in Java 5 (also called the "enhanced for loop"), is equivalent to using a java.util.Iterator – Alex78191 Commented Nov 21, 2019 at 19:10

  8. python - Inline for loop - Stack Overflow

    Jun 25, 2015 · I tried replacing the for loop with: [p.append(q.index(v)) if v in q else p.append(99999) for v in vm] But it doesn't work. The for v in vm: loop evicts numbers from vm …

  9. Python: Continuing to next iteration in outer loop

    In other languages you can label the loop and break from the labelled loop. Python Enhancement Proposal (PEP) 3136 suggested adding these to Python but Guido rejected it: However, I'm …

  10. What is the inteded way to use foreach in Python? [duplicate]

    Jun 26, 2019 · You imply that foreach loops don't exist in python, when, in fact, all for loops are foreach loops in python. The syntax is for var in iterable:, where iterable must be some object …

Refresh