How to go through two lists of different sizes [PYTHON]?

Asked

Viewed 562 times

1

The idea is as follows: Each team has 6 maps played (mapList) I made a web Rawler that takes all the information related to the team and the map and wanted to insert automatically in a spreadsheet using pandas. However I come across the following situation... He always stops at Fnatic which is the 6th team, because there are only 6 maps.

team = ["astralis", "Navi", "big", "Ence", "faze", "Fnatic", "furia", "heroic", "Liquid", "mibr", "mousesports","nip", "nrg", "Renegates","vitality","G2","Envy"]

mapList = ["Mirage", "Dust2", "inferno", "Nuke", "Overpass", "Train"]

...

t = 0
while t < len(team):
     for m in mapList:
          TesteTime = Time(team[t], m, 0,0,0,0,0,0)
          TesteTime.leitura(team[t], m)
          TesteTime.handicapMedio()
          TesteTime.HandicapVitoria()
          TesteTime.HandicapDerrota()
          TesteTime.rounds()
     t+=1

2 answers

1

 for t in team:
    for m in mapList:
        TesteTime = Time(team[t], m, 0,0,0,0,0,0)
        TesteTime.leitura(team[t], m)
        TesteTime.handicapMedio()
        TesteTime.HandicapVitoria()
        TesteTime.HandicapDerrota()
        TesteTime.rounds()
  • but the desired result is: astralis Mirage astralis Dust2 astralis inferno astralis Nuke astralis Overpass astralis Train And so on, which he already does, but when he reaches the fury he already stops and breaks the while

  • I edited the answer.

1


Matheus,

To do this you can do as in the example below:

team = ["astralis", "navi", "big", "ence", "faze", "fnatic", "furia", "heroic", "liquid", "mibr", "mousesports","nip", "nrg", "renegades","vitality","g2","envy"]
mapList = ["mirage", "dust2", "inferno", "nuke", "overpass", "train"]


for row_Team in team:
    for row_Map in mapList:
        print(row_Team + ' - ' + row_Map)

for will scroll through the team list, and each team will scroll through each map.

  • In terms of going through the list and printing the two joints really worked, but it still breaks when using the methods = Traceback (Most recent call last): File "bd.py", line 87, in <module> a.updatesCSV() File "bd.py", line 62, in updatedCSV Testetime.leitura(row_Team, row_Map) File "/home/coast/Desktop/trade_3.0/src/team.py", line 39, in reading self.resposta3 = filter.findall(line[26]) Indexerror: list index out of range

  • You did something like this ? &#xA;&#xA;for row_Team in team:&#xA; for row_Map in mapList:&#xA; print(row_Team + ' - ' + row_Map)&#xA; TesteTime = Time(row_Team, row_Map, 0,0,0,0,0,0)&#xA; TesteTime.leitura(row_Team, row_Map,)&#xA; TesteTime.handicapMedio() Testetime.Handicapvitoria() Testetime.Handicapdefeat() Testetime.rounds()

  • Yes, but when it reaches the seventh team, it stops and the: list index out of range

  • Try to pass the way I sent it. Because it would break if it passed via index as it is not believe it will not break this time.

  • I passed the way Voce did, without using index, the only difference is that print(row_Team + ' - ' + row_Map) is below . rounds()

  • It’s very strange because I did it here and it worked. I even divided it into two files. File 1: from test import testTime team = ["astralis", "Navi", "big", "Ence", "faze", "Fnatic", "furia", "heroic", "Liquid", "mibr", "mousesports","nip", "nrg", "Renegaes","vitality","G2"Envy"] mapList = ["mirage", "dust2", "inferno", "nuke", "overpass", "train"]&#xA;&#xA;for row_Team in team:&#xA; for row_Map in mapList:&#xA; teste = testTime()&#xA;&#xA; TesteTime = teste.TesteTime(row_Team, row_Map)&#xA; print(TesteTime)&#xA;&#xA;Arquivo 2:

  • File 2: class testTime: def Testetime(self, time, map): return = time + '-' + map Return return

  • Thus, PRINT works correctly, but when it arrives at the execution of the methods it works perfectly. I have already individually tested the methods and all work, but when I add the methods in the for, then it breaks and the list index out of range

  • It may be that when passing a team and a given map breaks within the method and not in the for.

  • Justissimo, I just checked my program takes the last 10 matches of each map, when it arrives in the fury she only has 2 matches on a map and breaks, thanks for opening my eyes!!

  • Good! ....... :)

Show 6 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.