Python day-Dictionary, 중첩 루프를 사용하는 문자 빈도
Jan 03, 2025 pm 05:54 PM사전-{}
--> 사전은 키:값 쌍으로 데이터 값을 저장하는 데 사용됩니다.
--> 사전은 순서가 지정되고 변경 가능하며 중복이 허용되지 않는 모음입니다.
-->사전에서 각 요소는 인덱싱을 통하지 않고 해당 키로 액세스할 수 있습니다.
-->사전에 키가 없으면 'KeyError'가 출력됩니다.
예:
thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 } student = {"name":"raja", "class":5} print(thisdict) print(student)
로그인 후 복사
출력:
{'brand': 'Ford', 'model': 'Mustang', 'year': 1964} {'name': 'raja', 'class': 5}
로그인 후 복사
연습:중첩 루프를 사용하여 문자열에서 문자 찾기
1. 문자열에서 각 문자의 빈도 찾기
s = 'guruprasanna' name = list(s) j = 0 while j<len(name): key = name[j] count = 1 i = j+1 if key != '*': while i<len(name): if key == name[i]: name[i] = '*' count+=1 i+=1 print(key, count) j+=1
로그인 후 복사
출력:
g 1 u 2 r 2 p 1 a 3 s 1 n 2
로그인 후 복사
*2. 문자는 한 번만 나타납니다 *
s = 'guruprasanna' name = list(s) j = 0 while j<len(name): key = name[j] count = 1 i = j+1 if key != '*': while i<len(name): if key == name[i]: name[i] = '*' count+=1 i+=1 if count == 1 and key!='*': print(key, count) j+=1
로그인 후 복사
출력:
g 1 p 1 s 1
로그인 후 복사
3. 가장 자주 쓰는 편지
s = 'guruprasanna' name = list(s) j = 0 while j<len(name): key = name[j] count = 1 i = j+1 if key != '*': while i<len(name): if key == name[i]: name[i] = '*' count+=1 i+=1 if count != 1 and key!='*': print(key, count) j+=1
로그인 후 복사
출력:
u 2 r 2 a 3 n 2
로그인 후 복사
4. 반복되지 않는 첫 번째 편지
s = 'guruprasanna' name = list(s) j = 0 while j<len(name): key = name[j] count = 1 i = j+1 if key != '*': while i<len(name): if key == name[i]: name[i] = '*' count+=1 i+=1 if count == 1 and key!='*': print(key, count) break j+=1
로그인 후 복사
출력:
g 1
로그인 후 복사
5. 첫 번째 반복 편지
s = 'guruprasanna' name = list(s) j = 0 while j<len(name): key = name[j] count = 1 i = j+1 if key != '*': while i<len(name): if key == name[i]: name[i] = '*' count+=1 i+=1 if count != 1 and key!='*': print(key, count) break j+=1
로그인 후 복사
6. 반복되지 않는 마지막 편지
last = ' ' last_count = 0 s = 'guruprasanna' name = list(s) j = 0 while j<len(name): key = name[j] count = 1 i = j+1 if key != '*': while i<len(name): if key == name[i]: name[i] = '*' count+=1 i+=1 if count == 1 and key!='*': last = key last_count = count #print(key, count) j+=1 print(last, last_count)
로그인 후 복사
출력:
s 1
로그인 후 복사
7. 마지막으로 반복되는 편지
last = ' ' last_count = 0 s = 'guruprasanna' name = list(s) j = 0 while j<len(name): key = name[j] count = 1 i = j+1 if key != '*': while i<len(name): if key == name[i]: name[i] = '*' count+=1 i+=1 if count != 1 and key!='*': last = key last_count = count #print(key, count) j+=1 print(last, last_count)
로그인 후 복사
출력:
n 2
로그인 후 복사
8. 가장 자주 쓰는 편지
s = 'guruprasanna' name = list(s) j = 0 last = ' ' last_count = 0 while j<len(name): key = name[j] count = 1 i = j+1 if key != '*': while i<len(name): if key == name[i]: name[i] = '*' count+=1 i+=1 if count != 1 and key!='*': if count>last_count: last = key last_count = count j+=1 print(last, last_count)
로그인 후 복사
9. 모음의 빈도(a,e,i,o,u)
vowels = ['a','e','i','o','u'] last = ' ' last_count = 0 s = 'guruprasanna' name = list(s) j = 0 while j<len(name): key = name[j] if key in vowels: count = 1 i = j+1 if key != '*': while i<len(name): if key == name[i]: name[i] = '*' count+=1 i+=1 if key!='*': print(key, count) j+=1
로그인 후 복사
출력:
u 2 a 3
로그인 후 복사
위 내용은 Python day-Dictionary, 중첩 루프를 사용하는 문자 빈도의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

인기 기사
스플릿 소설을이기는 데 얼마나 걸립니까?
3 몇 주 전
By DDD
Repo : 팀원을 부활시키는 방법
3 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌
헬로 키티 아일랜드 어드벤처 : 거대한 씨앗을 얻는 방법
3 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
1 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌

인기 기사
스플릿 소설을이기는 데 얼마나 걸립니까?
3 몇 주 전
By DDD
Repo : 팀원을 부활시키는 방법
3 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌
헬로 키티 아일랜드 어드벤처 : 거대한 씨앗을 얻는 방법
3 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
1 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌

뜨거운 기사 태그

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제
Gmail 이메일의 로그인 입구는 어디에 있나요?
7135
9


자바 튜토리얼
1534
14


라라벨 튜토리얼
1257
25


PHP 튜토리얼
1205
29


Cakephp 튜토리얼
1155
46



Tensorflow 또는 Pytorch로 딥 러닝을 수행하는 방법은 무엇입니까?
