• + 11 comments

    Hello my dear friends. How can I improve speed of my python code, which seems to do right calculations but it takes too long?

    totallist = [int(i) for i in input().split()]
    maxtopics = 0
    guyslist = []
    smarteams = 0
    for n in range(0, totallist[0]):
        guyslist += [str(input())]
    for i in range(0, totallist[0]-1):
        for j in range (i+1, totallist[0]):
           knowntopics = 0
           for q in range (0, totallist[1]):
              if int(guyslist[i][q]) or int(guyslist[j][q]): 
                 knowntopics += 1
           if knowntopics > maxtopics:
              maxtopics = knowntopics
              smarteams = 1
           elif knowntopics == maxtopics:
              smarteams += 1
    print (maxtopics)
    print (smarteams)