일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- 위니펙
- Deep learning
- mpnp
- MATLAB
- Plotting
- LV1
- 프로그래머스
- 머신러닝
- leetcode
- 방송통신대학교
- 알고리즘
- 컴퓨터과학과
- LAA
- cpp
- 코딩테스트
- 기본
- 주정부이민
- omscs
- 방통대
- 조지아텍
- EOI
- machine learning
- C++
- 딥러닝
- 캐나다 영주권
- 매트랩
- 선형대수
- 온라인석사
- zeros
- 개발자
Archives
- Today
- Total
Byte by Byte
python - string Module ) from collections import Counter 본문
from collections import Counter
str에 대해서, 각 char를 key로, 발생 빈도 수를 value를 하는 dict를 만들어줌.
str = "hello"
Counter(str) 하면 , { 'h' : 1 , 'e' : 1 , 'l' : 2, 'o' : 1 }
이렇게 나옴.
dict for loop 는
for key, value in {dict}.items():
class Solution:
def canConstruct(self, ransomNote: str, magazine: str) -> bool:
from collections import Counter
rans = Counter(ransomNote)
magz = Counter(magazine)
for key,value in rans.items():
rans[key] = rans[key]-magz[key]
for key,value in rans.items():
if rans[key] > 0:
return False
return True
'개발 로그 > 알고리즘' 카테고리의 다른 글
442. Find All Duplicates in an Array.cpp (0) | 2022.01.24 |
---|---|
1854. Maximum Population Year.cpp (0) | 2021.12.17 |
49. Group Anagrams.cpp (0) | 2021.12.16 |
1078. Occurrences After Bigram.cpp (0) | 2021.12.15 |
1598. Crawler Log Folder.cpp (0) | 2021.12.15 |