2016-06-14 3 views
-2

에 텍스트의 목록을 분할하는어떻게이 목록이 단어의 목록 파이썬

["This", "Is", "A"] ... 

을 내가 어떻게이

+0

당신이 임의의 공백에 분할 할 마십시오 단지 하나의' ""'? – erip

+0

Google에 알려주십시오. "문장을 단어로 분할" http://stackoverflow.com/questions/743806/split-string-into-a-list-in-python –

+2

일부 Python 코드를 작성합니다. – jonrsharpe

답변

1

이렇게 할 수 있습니다.

a = "This is a set of words and it is not correct" 
[i.capitalize() for i in a.split()] 

질문에 언급 된대로 입력하면 list입니다.

a = ["This is a set of words and it is not correct"] 
[i.capitalize() for i in a[0].split()] 

출력

[ '이것은', '인가', 'A가', '중', '설정', '단어', '그리고', '이', ' ','가능하지 않음 ', '올바른 ']

0

사용 split() 방법

>>> foo = ["This is a set of words and it is not correct"] 
>>> foo[0].split() 
['This', 'is', 'a', 'set', 'of', 'words', 'and', 'it', 'is', 'not', 'correct'] 
3
"This is a set of words and it is not correct".title().split() 

출력 :

['This', 'Is', 'A', 'Set', 'Of', 'Words', 'And', 'It', 'Is', 'Not', 'Correct'] 
+0

'str.title'은 꽤 귀엽다. – erip

관련 문제