1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97  | # ====== 1번 문제 ====== user_input = list(input().split()) # loving can heart loving can mend your soul user_input_word = list(set(user_input)) # set()함수를 사용하면 자동으로 중복이 제거된다 user_input_word # 어떤 단어들이 입력되는지 본다 print(len(user_input_word)) # ====== 2번 문제 ====== string = "ABCABCDABCABEABCDEFBCABCCA" string.count("BCA") # ====== 3번 문제 ====== print("숫자와 알파벳으로 구성된 문자열을 입력받아서 숫자만큼 알파벳을 반복시켜 변환하는 함수를 구하시오") user_input = list(input("숫자와 알파벳으로 구성된 문자열을 입력하세요:\nEX> 2a5b1c\n")) # 사용자의 입력을 받는 변수를 만들어준다. # uncompress 함수를 정의해 준다 def uncompress(input):     conversion = int(input[0])*input[1]+int(input[2])*input[3]+int(input[4])*input[5]     return conversion print(uncompress(user_input)) # ====== 4번 문제 ====== # v1. 노가다 버전 str = input("Enter one word: ") vowel_a = 0 vowel_e = 0 vowel_i = 0 vowel_o = 0 vowel_u = 0 for i in str:     if i == 'a':         vowel_a += 1     elif i == 'e':         vowel_e += 1     elif i == 'i':         vowel_i += 1     elif i == 'o':         vowel_o += 1     elif i == 'u':         vowel_u += 1 print(vowel_a) print(vowel_e) print(vowel_i) print(vowel_o) print(vowel_u) # v2. dicionary활용 def histogram(h):     d = dict() # 문자의 개수를 counting할 dictionary 생성     for c in h:         if c not in d:             d[c] = 1 # 문자 c가 딕셔너리에 없으면, 키가 c이고 초기값이 1인 새 항목을 만들어준다.         else:             d[c] +=1 # 문자 c가 딕셔너리에 있다면, 키가 c인 값의 value값을 1씩 증가시켜준다     return d def print_hist(h):     for c in h:         print(c, h[c]) h = histogram(input('Enter one word: ')) print_hist(h) # v3. aeiou counting  - 모음 전체 카운팅 def histogram(h):     count = 0     for c in h:         if c not in 'aeiou':             count += 1 # c가 모음에 속한다면 count를 1씩 증가시켜라     return count h = histogram(input('Enter one word: ')) print(h) # 모음을 하나하나 세는 방법을 잘 모르겠습니다.. # v4.  user_input = input("Enter one word: ") search = user_input.lower() d = {d:search.count(d) for d in 'aeiou'} d # 참고:: https://stackoverflow.com/questions/19967001/count-vowels-in-string-python # ====== 5번 문제 ====== def all_perms(word):     if len(word) <=1:         return word     else:         tmp = []         for perm in all_perms(word[1:]):             for i in range(len(word)):                 tmp.append(perm[:i] + word[0:1] + perm[i:])         return tmp user_input = input("input one word: ") print(all_perms(user_input)) print(len(all_perms(user_input))) # 참고: https://stackoverflow.com/questions/11989502/producing-all-the-anagrams-from-a-string-python  | cs | 
'Deep Learning > 밑바닥부터 시작하는 데이터 과학' 카테고리의 다른 글
| 01. 머신러닝/딥러닝을 위한 수학 및 확률과 통계 가이드 - KOCW와 기본 서적 추천 (0) | 2020.05.28 | 
|---|---|
| Intro. 밑바닥부터 시작하는 데이터 과학 (2) | 2020.05.26 | 
| [Python]구구단 계산기 (0) | 2019.01.09 | 
| [python]학점계산기(exam_grader)_by.Teamlab (2) | 2019.01.08 | 
| [Pandas튜토리얼]Pandas Data analysis (0) | 2018.12.03 | 
										
									
										
									
댓글