#1
10820 문자열 분석
각 문장마다 소문자, 대문자, 숫자, 공백을 세서 프린트하면 되는 문제
import re
import sys
while True:
sentence = sys.stdin.readline().rstrip('\n')
if not sentence:
break;
s = len(re.findall('[a-z]',sentence))
l = len(re.findall('[A-Z]',sentence))
n = len(re.findall('[0-9]',sentence))
b = len(re.findall(' ', sentence))
print(s,l,n,b)
#2
2857 FBI
주어지는 이름들 중, FBI를 포함하고 있는 것 찾기
import re
answer = []
for i in range(5):
codeName = input()
fbi = len(re.findall("FBI",codeName))!=0
if fbi:
answer.append(i+1)
if len(answer)==0:
print("HE GOT AWAY!")
else:
print(*answer)
===
리스트의 대괄호 제거하기
-> * 붙이기
print(answer)
=> [ 1 3 5 ]
print(*answer)
=> 1 3 5
이렇게 출력. 리스트의 이름 앞에 * 를 붙이면 언패킹된다.
#3
8595 히든 넘버
주어진 단어안에 숨어있는 히든 넘버의 합을 출력하기
=> 히든 넘버 조건 : (1) 연속된 숫자 (2) 두 히든 넘버 사이에는 글자가 적어도 한 개 있다 (3) 히든 넘버는 6자리를 넘지 않는다.
import re
N = int(input())
sentence = input()
'''
[0-9]{1,6}
0 부터 9 까지 이루어진 숫자 중에
한 자리부터 6자리까지 찾아라
예를 들어, abc123asd4asdf29009asdf29
이렇게 있다면
123 4 29009 29 이렇게 리턴될 것
'''
answer = re.findall('[0-9]{1,6}',sentence)
answer = list(map(int,answer))
if len(answer)==0:
print("0")
else:
print(sum(answer))