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 make this Python code faster?
Posted by Neeraj Kumar 3 Jan 2016 10:09
import sys
p = input()
p_list = []
for i in range(int(p)):
    x = input()
    p_list.append(x)
s = input()
s_list = []
for i in range(int(s)):
    x = input()
    s_list.append(x)

count = 0
l = set(s_list).intersection(p_list)

for i in l:
    count += s_list.count(i)

print (count)
Re: TLE #8: How can I make this Python code faster?
Posted by SMMaster 30 Dec 2019 14:30
import sys
ll = set()
for i in range(int(sys.stdin.readline())):
    ll.add(sys.stdin.readline())
n = 0
for j in range(int(sys.stdin.readline())):
    if sys.stdin.readline() in ll:
        n += 1
print(n)