When you do for i in row, i takes the values in row, i.e. '1', then '2', then '3'.

Those are strings, which are not valid as a list index. A list index should be an integer. When doing range(len(row)) you loop on integers up to the size of the list.

By the way, a better approach is:

for elt_id, elt in enumerate(list):
    # do stuff
Answer from Mathieu on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_lists_loop.asp
Python - Loop Lists
Remove List Duplicates Reverse a String Add Two Numbers ยท Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... Learn more about for loops in our Python For Loops Chapter.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ iterate-over-a-list-in-python
Iterate over a list in Python - GeeksforGeeks
We can use the range() method with for loop to traverse the list. This method allow us to access elements by their index, which is useful if we need to know the position of an element or modify the list in place.
Published ย  December 27, 2025
Discussions

Iterating over a list in python using for-loop - Stack Overflow
I have a question about iterating over a list in python. Let's say I have a list: row = ['1', '2', '3'] and want to convert its element to integers, so that: row = [1, 2, 3]. I know I can do it w... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Is it possible to iterate over a list of lists in a function?
You could use a nested list comprehension, eg. def func(*args): return [ele for sublist in zip(*args) for ele in sublist] This type of operation is known as flattening a list. In this case we are flattening the output of zipping all the sublists. More on reddit.com
๐ŸŒ r/learnpython
16
6
May 31, 2021
python - How to loop over a list of lists - Stack Overflow
The lists only have one element but they're still stored within a list. When you use x[0] you're telling Python you want to access the first element of each list, which is the number you want. Also another thing you could do which would be faster than a for loop is to use list comprehension: More on stackoverflow.com
๐ŸŒ stackoverflow.com
Iterate through a list and perform an action for each item in the list
There will probably be a more elegent way to do this (and I hope someone can point this out to me) but this should work: for i, item1 in enumerate(desciption_list): for j, item2 in enumerate(desciption_list): if j <= i: continue else: print(jaro_distance(str(item1), str(item2)) Just found this on StackOverflow : import itertools for a, b in itertools.combinations(mylist, 2): print(jaro_distance(a, b)) More on reddit.com
๐ŸŒ r/learnpython
7
29
November 12, 2021
๐ŸŒ
EITCA
eitca.org โ€บ home โ€บ how can we iterate over a list of lists using a "for" loop in python?
How can we iterate over a list of lists using a "for" loop in Python? - EITCA Academy
August 3, 2023 - To iterate over a list of lists using a "for" loop in Python, we can make use of nested loops. By nesting a "for" loop inside another "for" loop, we can traverse through each element in the outer list and then iterate over the inner lists. Here's an example to illustrate the process: python ...
๐ŸŒ
StrataScratch
stratascratch.com โ€บ blog โ€บ looping-through-lists-in-python
Looping Through Lists in Python: A Comprehensive Tutorial - StrataScratch
April 9, 2025 - Python provides ways to change your loops' order without altering your original list. But itโ€™s helpful when order matters or youโ€™re unwinding something step by step. fruits = ['apple', 'banana', 'cherry'] for fruit in reversed(fruits): print(fruit) You iterate over them as you would any list.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ is it possible to iterate over a list of lists in a function?
r/learnpython on Reddit: Is it possible to iterate over a list of lists in a function?
May 31, 2021 -

I have this exercise I am tring online which take a bunch of lists and zip them together. first and then returns a list. For example, the input func([1,2,3], [20,30,40], ['a', 'b', 'c']) should return [1, 20, 'a', 2, 30, 'b', 3, 40, 'c']

However I do not know how to iterate over the list. I don't even know if it's possible. I tried

def func(*args):
    for n in args:
        ans = list(zip(n))
        return ans

But I just get : [(1,), (2,), (3,)]

Find elsewhere
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-to-iterate-over-a-list-in-python
How to iterate over a list in Python
If you want to use a list inside a for loop, just reference its name: my_list = [10, 20, 30] for item in my_list: print(item) ... These methods work efficiently for iterating through a list of words in Python.
๐ŸŒ
Kansas State University
textbooks.cs.ksu.edu โ€บ intro-python โ€บ 07-lists โ€บ 03-loops-lists
Loops with Lists :: Introduction to Python
June 27, 2024 - Resources Slides One great way to work with lists in Python is using a loop. Recall from an earlier lab that a for loop actually iterates over a list itself, and that the range() function is simply used to generate a list that the for loop can use. Likewise, while loops can also be used in ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ iterate-over-a-list-of-lists-in-python
Iterate Over a List of Lists in Python - GeeksforGeeks
July 23, 2025 - List comprehension flattens the nested list into a single list. "b" contains all elements from "a" in one dimension. We can use enumerate() to track indices while iterating, which is helpful when we want to know the position of each sublist. ... a = [['Python', 'Java'], ['C++', 'C#'], ['Go', 'Rust']] for i, g in enumerate(a, start=1): print(f"Group {i}: {g}")
๐ŸŒ
DZone
dzone.com โ€บ coding โ€บ languages โ€บ how to iterate over multiple lists sequentially in python
Iterate Over Multiple Lists Sequentially in Python
May 20, 2024 - The second approach is where you need to process the first item of each list then the second item of each list and so on. In the first case, you can use the itertools.chain() function, a for loop, or a star(*) operator.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ iterate through a list and perform an action for each item in the list
r/learnpython on Reddit: Iterate through a list and perform an action for each item in the list
November 12, 2021 -

Hi, so I am quite new to python however have an issue I am struggling to come up with convincing solution to.

I have a list of strings - around 27 items - and have also created a function that calculates the Jaro distance between the two String variables, this works as far as I can tell however I now need to form a loop that will allow me to apply this function for each item in the list against each other item in the list.

So far I have been using the following for loop:

for i in description_list:
    print(jaro_distance(str(description_list[1]),str(description_list[count+1])))     
    count = count + 1

print(jaro_distance(str(description_list[1]), str(description_list[count+1]))) count = count + 1

but this only works for comparing the fist item in the list vs the following items. So my question is this, how can I create a loop that iterates each item against every other item in the list?

๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ itertools.html
itertools โ€” Functions creating iterators for efficient looping
February 24, 2026 - Loops over the input iterable and accumulates data into tuples up to size n. The input is consumed lazily, just enough to fill a batch. The result is yielded as soon as the batch is full or when the input iterable is exhausted: >>> flattened_data ...
๐ŸŒ
Analytics Vidhya
analyticsvidhya.com โ€บ home โ€บ 6 ways to iterate over a list in python
6 Ways to Iterate over a List in Python - Analytics Vidhya
May 22, 2025 - Letโ€™s explore each of them in detail: A for loop is the most common and straightforward method to iterate over a list. The for loop lets us iterate over each list element and perform a specific operation.
๐ŸŒ
Medium
medium.com โ€บ @ryan_forrester_ โ€บ how-to-iterate-over-lists-in-python-8624f38ad9fc
How to Iterate Over Lists in Python | by ryan | Medium
October 28, 2024 - Python offers many ways to iterate over lists, each suited to different needs: - Use simple for loops for basic iteration - Choose enumerate() when you need indices - Pick list comprehensions for transformations - Select zip() for parallel iteration - Use reversed() for backward processing - Apply slicing for partial processing
๐ŸŒ
LearnPython.com
learnpython.com โ€บ blog โ€บ python-list-loop
7 Ways to Loop Through a List in Python | LearnPython.com
Pythonโ€™s lambda function is an anonymous function in which a mathematical expression is evaluated and then returned. As a result, lambda can be used as a function object. Letโ€™s see how to use lambda as we loop through a list. Weโ€™ll make a for loop to iterate over a list of numbers, find each number's square, and save or append it to the list.
๐ŸŒ
GUVI
guvi.in โ€บ hub โ€บ python โ€บ iterate-over-a-list-in-python
Iterate Over a List in Python: Loops Made Easy
Using a 'for' loop: The 'for' loop is a simple and effective way to iterate over a list in Python. It iterates over each element in the list and executes a block of code for each iteration.
๐ŸŒ
Codecademy
codecademy.com โ€บ learn โ€บ dspath-python-lists-and-loops โ€บ modules โ€บ dspath-loops โ€บ cheatsheet
Python Lists and Loops: Python Loops Cheatsheet | Codecademy
# List comprehension for the squares of all even numbers between 0 and 9 ... A Python for loop can be used to iterate over a list of items and perform a set of actions on each item.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_for_loops.asp
Python For Loops
Remove List Duplicates Reverse ... Interview Q&A Python Bootcamp Python Certificate Python Training ... A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a stri...
๐ŸŒ
Quora
quora.com โ€บ How-do-you-loop-over-lists-in-Python
How to loop over lists in Python - Quora
Answer (1 of 5): List is equivalent to arrays in other languages, with the extra benefit of being dynamic in size. In Python, the list is a type of container in Data Structures, which is used to store multiple data at the same time. Unlike Sets, lists in Python are ordered and have a definite cou...