ysj1375   2년 전

a = input().split()

print(len(a))

이건 정답이고

a = input().split(" ")

print(len(a))

이건 오답입니다

반례같은게 있을까요? 뭐가 다른지 gpt쳐도 모르겠습니다

renkousami   2년 전

파이썬 공식 문서(https://docs.python.org/3.8/library/stdtypes.html#str.split) :

If sep is not specified or is None, a different splitting algorithm is applied: runs of consecutive whitespace are regarded as a single separator, and the result will contain no empty strings at the start or end if the string has leading or trailing whitespace. 

' '를 seperator로 지정하면 ' '마다 끊게 되어, 예를 들어 '  a'는 ['', '', 'a']로 끊게 되는 반면 지정하지 않을 경우 자동으로 어떤 길이의 공백이든 하나의 seperator로 취급해 끊어주는 알고리즘이 작동하므로 이 문제를 풀기 쉬운 방법이 됩니다.

댓글을 작성하려면 로그인해야 합니다.