0
a = []
for index in range(52):
    a.append([])
    for jindex in range(52):
        a[index].append('a')

row,col = [int(x) for x in input().split(" ")]

b = []

for index in range(row):
    str = input()
    for jindex in range(col):
        a[index+1][jindex + 1] = str[jindex]
        if(str[jindex] == 'A'):
            b.append([index,jindex])

#print (a)
# print (b)

ans = max(trav(x[0],x[1]) for x in b

The last line is troublesome, trav(r,c) is a function that return integer values.

I just want to ask is this usage correct? I am very new to python. I tried to extend this line from row,col = [int(x) for x in input().split(" ")]

I am trying to store the max value the function trav returns for each list of 2 items stored in the list b.

Like: if the list b is [[10, 20], [2, 3]] and lets say the func trav returns the sum of the 2 items in the sublist.

then the first sub list gives us 30, and then second gives us 5. So ans should have a value 30

4

1 回答 1

2

You should be able to just add the missing right parenthesis at the very end of the last line. The trav(x[0],x[1]) for x in b forms a generator expression that generates the value of trav for each element of b, and then max() iterates over that generated sequence and returns the maximum value found.

于 2013-03-30T20:57:31.127 回答