Skip to content
Advertisement

Adding a different value to a list based on number of iteration in a for loop

I’m new to Python and programming in general and I am having trouble with a website parsing project.

This is the code I managed to write:

JavaScript

What I’m trying to do and can’t find a solution to, is to add to item_list the name of the item which the url refers to.

e.g.

index platinum quantity items name (problematic column)
1 10 1 melee_riven_mod_(veiled)
2 11 1 melee_riven_mod_(veiled)
3 12 2 zaw_riven_mod_(veiled)
4 zaw_riven_mod_(veiled)

But items name column has the same name for all the rows like this:

index platinum quantity items name (problematic column)
1 10 1 melee_riven_mod_(veiled)
2 11 1 melee_riven_mod_(veiled)
3 12 2 melee_riven_mod_(veiled)
4 melee_riven_mod_(veiled)

So I wanted to ask what am I doing wrong in the for loop? It iterates 2 times which is the amount of urls in the url_list but it doesn’t change the name of the item. What am I not seeing?

Advertisement

Answer

Change

JavaScript

To this:

JavaScript

Note, that instead of having a separate variable iteration and incrementing it, you can loop over url_list using enumerate, which provides both the item and its index at each iteration:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement