파이썬 for 반복문 질문있습니다 ㅜㅜ

매출이 오르면 내리는 수수료! 지금 수수료센터에서 전자결제(PG)수수료 비교견적 신청해 보세요!
파이썬 for 반복문 질문있습니다 ㅜㅜ

QA

파이썬 for 반복문 질문있습니다 ㅜㅜ

본문

글자 수 세기 문제를 풀고 있는데요

출력했을 때

text = []

sentence = input()

sentence = sentence.upper()

for a in sentence:

text.append(a)

for b in text:

if ord(b) == 32:

text.remove(b)

for c in text:

print('"',c ,'"',":",text.count(c))


hello world; Algorithm world!!
" H " : 2
" E " : 1
" L " : 5
" L " : 5
" O " : 4
" W " : 2
" O " : 4
" R " : 3
" L " : 5
" D " : 2
" ; " : 1
" A " : 1
" L " : 5
" G " : 1
" O " : 4
" R " : 3
" I " : 1
" T " : 1
" H " : 2
" M " : 1
" W " : 2
" O " : 4
" R " : 3
" L " : 5
" D " : 2
" ! " : 2
" ! " : 2


같은 문자가 이렇게 중복돼서 나오는데 중복되는 건 어떻게 없애나요...?? ㅠㅠ

이 질문에 댓글 쓰기 :

답변 2

중복되지않는 값만 새로운 배열에 넣으세요

text = []
newArr = []
sentence = input()

sentence = sentence.upper()

for a in sentence: text.append(a)

for b in text:

   if ord(b) == 32: text.remove(b)
   elif b not in newArr : newArr.append(b)

for c in newArr: print('"',c ,'"',":",text.count(c))

 

답변을 작성하시기 전에 로그인 해주세요.
전체 208
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT