About 50 results
Open links in new tab
  1. Iterating over a list in python using for-loop - Stack Overflow

    Aug 8, 2018 · And it can be incorporated in a list comprehension. You have 3 scenarios: 1 you need to iterate on the element in the list, then simply use for elt in list:, 2 you only need the indexes, 3 you will …

  2. Which is the most efficient way to iterate through a list in python?

    Jun 12, 2012 · 5 Another possible solution would be to use numpy which would be very efficient, for large lists perhaps even more efficient than a list comprehension or a for loop.

  3. python - How do I loop through a list by twos? - Stack Overflow

    Closed 6 years ago. I want to loop through a Python list and process 2 list items at a time. Something like this in another language:

  4. How to iterate through a list of dictionaries - Stack Overflow

    Aug 6, 2025 · There are multiple ways to iterate through a list of dictionaries. However, if you are into code, consider the following ways, but first, let's use instead of because in Python snake_case is …

  5. python - iterating through a list with an if statement - Stack Overflow

    May 28, 2011 · 13 I have a list that I am looping through with a "for" loop and am running each value in the list through an if statement. My problem is that I am trying to only have the program do something …

  6. python - Loop through a list of pandas DataFrames and perform ...

    Jun 19, 2017 · This is a basic question, but I want to loop through a list of DataFrames and for each DataFrame, set the index as one of the columns in the DataFrame. The issue with the code below is …

  7. python - Loop through list with both content and index - Stack Overflow

    It is very common for me to loop through a python list to get both the contents and their indexes. What I usually do is the following: S = [1,30,20,30,2] # My list for s, i in zip (S, range (len (S))...

  8. python - How to remove items from a list while iterating ... - Stack ...

    Oct 23, 2012 · I'm iterating over a list of tuples in Python, and am attempting to remove them if they meet certain criteria. for tup in somelist: if determine(tup): code_to_remove_tup What should ...

  9. loops - Traverse a list in reverse order in Python - Stack Overflow

    Feb 10, 2009 · How do I traverse a list in reverse order in Python? So I can start from collection[len(collection)-1] and end in collection[0]. I also want to be able to access the loop index.

  10. Loop Through List and Restart at Beginning - Stack Overflow

    Nov 16, 2021 · I have a list and I want to be able to return each item in sequence and when it reaches the last item (a7) continue running from the beginning. An added complexity is that the script will not run