'카운팅'에 해당되는 글 1건

  1. 2012.10.26 [Python] 문자열을 입력받아 단어 카운팅
Programming/Python2012. 10. 26. 10:13


학교 중간고사 시즌입니다.

"정보 검색"이란 과목은 중간고사 대신 프로젝트 제출로 하라고 하셔서

한번 만들어 봤습니다.

 

프로그래밍 언어에 조건이 없어서

이전에 해보고 싶어하던 파이썬을 이용해서 만들어 보았습니다.

 

더 라인 수를 줄일 수 있을 것 같은데...

파이썬으로 처음 만들어본 소스다 보니...ㅠㅠ

 

-----------------Information search - midterm project---------------

 

***Project: Extract the words from a set of text****

example:
The South Korean government is
on of the leading countries in Asia.
It is a government that makes
other countries strive hard.

the - 2
south - 1
korean - 1
government -2
is - 2
------
***

--------------------------------------------------------------------

 

아래는 코드..

--------------------------- 07050053_midterm.py --------------------

import os
str = raw_input("in :")
str2 = str.lower()
str3 = str2.split()
for word in str3:
 print "%s - %d"%(word,str3.count(word))
 for q in range(str3.count(word)):
  str3.remove(word)
os.system("pause")
--------------------------------------------------------------------

 

exe 로 변경시 결과를 출력하고 바로 종료시키기 때문에

os 를 포함시킨후 pause 로 멈추는 걸 추가하다보니 2줄이 더 길어졌네요..

 

평소 많이 쓰던 C나 타 언어로는 상상할 수 없던 라인 수네요.. 7줄..

굉장히 매력적인 언어인 것 같습니다..

Information Search midterm.zip

'Programming > Python' 카테고리의 다른 글

Python을 하나의 exe 파일로 변환하기.  (0) 2012.10.26
Posted by NullBr4in