split 함수를 쓰면 리스트로 담긴다
name = 'first.middle.last'
#구분자 없이
call = name.split()
print(call)
#구분자 포함
call = name.split('.')
print(call)
>> ['first.middle.last']
>> ['first','middle','last']
리스트로 담기기 때문에 원하는 것만 따로 불러낼 수 있음
Ex) BOJ/백준 20291 - 파일 정리
여기서 뒤에 파일 확장자명만 필요하다. split 함수를 이용해 확장자명만 바로 받아보자.
array = []
for _ in range(int(input())):
extens = input().split('.')[1]
array.append(extens)
print(array)
>> ['txt','spc','icpc','icpc','txt','world','spc','txt']
'Web > django & python' 카테고리의 다른 글
[Python] 함수 isalnum() , isalpha() (0) | 2022.01.21 |
---|---|
[Python] input, sys.stdin.readline 차이점 (2) | 2022.01.19 |
[Python] 리스트(list) 원소들 문자열(str)로 합치기 (0) | 2022.01.18 |
[Python] 딕셔너리(dictionary) 값 추가, 삭제, key 또는 value 불러오기 (0) | 2022.01.18 |
[Django] Form으로 checkbox의 value 전달을 위한 submit : button vs input (0) | 2021.09.03 |