ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1196. History Exam

TLE 8. How can I optimise my code? (Python)
Posted by Maksim 31 Oct 2022 21:40
N =int(input())
Nl = []

for i in range(N):
    Nl.append(int(input()))

M = int(input())
Ml = []

for j in range(M):
    Ml.append(int(input()))

answerl = []


Nl = set(Nl)
Nl = list(Nl)
Nl.sort()

for ni in Nl:
    for mi in Ml:
        if mi == ni:
            answerl.append(mi)
        else:
            continue

print(len(answerl))
Re: TLE 8. How can I optimise my code? (Python)
Posted by ixiolirion 1 Nov 2022 08:23
https://docs.python.org/3/library/stdtypes.html#set

x in s
    Test x for membership in s.