So I have two lists in Python. Both are lists of lists. When I print rows individually they look like this (except much bigger):
PROBABLES
['Name10', 'Ari']
['Name11', 'Atl']
['Name12', 'Bal']
['Name13', 'Bos']
['Name14', 'ChC/CWS']
['Name15', 'Cin']
['Name15', 'Cle']
['Name16', 'Col']
['Name17', 'ChC/CWS']
['Name18', 'Det']
SALARIES
['SP', 'Name1', '6900', 'Tor', '@', 'Sea']
['SP', 'Name2', '6900', 'Hou', '@', 'KC']
['SP', 'Name3', '6900', 'LAD', '@' 'NYM']
['SP', 'Name4', '6800', 'ChC', '@', 'Phi']
The problem is that for the second value in the Probables list, sometimes they'll have two things in it. See example above, the ones with slashes. What I want to do is replace that value with the correct one (basically selecting the correct one). The way I've decided is the best way to go about this is comparing to a second list.
In the end, for example, the 5th row in Probables would read ['Name14', 'ChC'] if Name14 in Probables was the same as Name4 in Salaries. Here's the code I've got so far.
for row in probables:
if '/' in row[1]:
a = row[0] #Name from probables list
b = row[1] #Abbrev. of team
for row in salaries:
if row[1] == a:
c = row[3] #First team involved in game
d = row[5] #Second team involved in game
if b == c:
row[1] = c
elif b == d:
row[1] = d
This gives me the error "Traceback (most recent call last): File "C:\Users\Owner\Desktop\Test\matching test.py", line 21, in if b == c: NameError: name 'b' is not defined"
I'm assuming this has to do with how variables work and are defined inside of loops, but I don't know how to fix it. Any help? Thanks.
row[1] == a, which also depends on ` '/' in row[1]`pitcher[1] = cin your posted code.