Python 문장에서 단어 갯수카운트

빌트인 기능인 map()을 사용해서 문장에서 단어를 끊어서 문자개수를 세우는 방법입니다.

phrase = ‘How long are the words in this phrase’

map(lambda word: len(word), phrase.split())

결과>> [3, 4, 3, 3, 5, 2, 4, 6]

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s