About 58,400 results
Open links in new tab
  1. python - Get loop count inside a for-loop - Stack Overflow

    Get loop count inside a for-loop [duplicate] Asked 15 years, 5 months ago Modified 3 years, 7 months ago Viewed 654k times

  2. Python loop counter in a for loop - Stack Overflow

    Closed 6 years ago. In my example code below, is the counter = 0 really required, or is there a better, more Python, way to get access to a loop counter? I saw a few PEPs related to loop counters, but …

  3. for loop in python with counter? - Stack Overflow

    How can I create a for loop with a counter? I have a list, and I want to read an element after each n elements. I'd initially done this for i in enumerate(n): print(i) But as expected it prints

  4. What is a counter and how is it used in Python loops?

    May 29, 2023 · A counter keeps count of how many times the program iterates through the loop. In your first code example, the variable n is the counter. In your second example, i is the counter. In many …

  5. python - How to add a counter to a while loop? - Stack Overflow

    I have used a while loop in this but sometimes it gets stuck, is there a way to add a counter to the guesses taken, and to break the while loop after 5 incorrect guesses? Here is a section of my code …

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

    A loop with a "counter" variable set as an initialiser that will be a parameter, in formatting the string, as the item number. The for loop accesses the "listos" variable which is the list.

  7. python - adding a counter in a for loop - Stack Overflow

    Apr 13, 2016 · A while loop is the correct tool - you don't want to enumerate all values of x from 0-20 (as a for loop would do), you want to execute a block of code while x < 20.

  8. iteration - Pythonic way to iterate over a collections.Counter ...

    In Python 2.7, I want to iterate over a collections.Counter instance in descending count order.

  9. Creating a counter inside a Python for loop - Stack Overflow

    Dec 1, 2016 · You are strongly recommended to always use Python's built-in functions for creating "pythonic solutions" whenever possible. There is also the documentation for enumerate. If you need …

  10. How to increment counter in for loop for python? - Stack Overflow

    Mar 12, 2017 · I'm just trying to increment a simple counter in my for loop, but this function always returns 54. I'm guessing it does this because it sees the second counter as a local variable inside the …