[백준 파이썬 1764번]듣보잡★DICTIONARY 활용하기★SORT()함수★VER2.0
2023. 4. 10. 19:25
728x90
반응형
https://www.acmicpc.net/problem/1764
VERSION 2.0
import sys
N,M = list(map(int ,sys.stdin.readline().split()))
dic = {}
for i in range(1,N+1):
dic[sys.stdin.readline().rstrip()] = i
res = []
for j in range(M):
a = sys.stdin.readline().rstrip()
if dic.get(a):
res.append(a)
print(len(res))
for k in sorted(res):
print(k)
==> get() 할때 value값이 0이면 출력이 안된다. 1로 바꿔주자!
VERSION 1.0
import sys
N = list(map(int , sys.stdin.readline().rstrip().split()))
S= {}
for i in range(N[0]):
S[i] = sys.stdin.readline().rstrip()
#S = {0 : "a" ,1 : "b" , 2 : "c"}
#print(S)
cnt = 0
res = []
T = {k:v for v,k in S.items()}
# T = {"a" : 0 , "b" : 1 , "c" : 2}
for i in range(N[1]):
a = sys.stdin.readline().rstrip()
if T.get(a) is not None: #듣보잡 명단에 포함되어 있다면
cnt+=1
res.append(S.get(T.get(a)))
print(cnt)
res.sort()
for i in res:
print(i)
★중요 POINT★
T = {k:v for v,k in S.items()} ==> 집합의 KEY : VALUE 값 변환
sorted(a, reverse = True) ==> 그 위치에서만 변환
sort() ==> 리스트 자체 변환
728x90
반응형
'Python(백준) > 집합과 맵' 카테고리의 다른 글
[백준 파이썬 11478번]★SET활용하기★add()★튜플 (0) | 2023.04.10 |
---|---|
[백준 파이썬 1269번]대칭차집합★SET활용하기★VER2.0 (1) | 2023.04.10 |
[백준 파이썬 10816번]숫자카드2★Counter() 활용★DICTIONARY 활용하기★VER4.0 (1) | 2023.04.10 |
[백준 파이썬 1620번]나는야 포켓몬★DICTIONARY 이해!!!★isnumeric★get() (1) | 2023.04.10 |
★del()★dictionary활용하기★[백준 파이썬 7785번]회사에 있는 사람 (0) | 2023.04.10 |