A ship in harbor is safe, but that is not what ships are built for.

개발일지/AI 캠프

내일배움캠프 AI - 10일차 TIL, 2022.09.13

플리피나리 2022. 9. 13. 21:00
반응형

스파르타 코딩클럽 내일배움캠프 AI 웹개발자양성과정 3회차

2022.09.13. 10일차 - TIL

 

1. Git 특강

  • vi/vim 편집기
- a와 i를 입력해 INSERT로 내용 삽입 가능
- 입력 종료 후 ESC + :wq로 저장하고, vi/vim 창을 닫음
  • 버전 만들기(☆★별표 다섯개)
로컬 저장소 만들기
$ git init

스테이지에 추가하기
$ git add <파일이름> <파일이름>

현재 작업 디렉터리의 변경 사항을 모두 스테이지에 추가하기
$ git add .

커밋하기(메세지 헤더만 작성)
$ git commit -m "커밋 메세지 헤더"

자세한 커밋 메세지로 커밋하기
$ git commit

스테이지에 추가와 커밋 동시에 하기
$ git commit -am "커밋 메세지 헤더"
  • 버전 조회하기
현재 커밋들의 목록 조회하기
$ git log

현재 커밋들의 목록 한 줄로 조회하기
$ git log --oneline

현재 커밋들의 목록 + 각 커밋들의 변경사항까지 확인하기
$ git log -p

현재 커밋들의 목록을 그래프 형태로 조회하기
$ git log --graph

혼용하여 사용하기
$ git log --oneline --graph
$ git log --oneline -p
  • 비교하기
현재 작업 디렉터리에서의 작업 내역과 최신 커밋을 비교하기
$ git diff

스테이지와 작업 내역과 최신 커밋을 비교하기
$ git diff --staged

커밋끼리 비교하기
$ git log <커밋해시> <커밋해시>
  • 되돌리기(☆많이 연습해보기!)
특정 커밋을 취소한 새로운 커밋 생성 -> 기존의 커밋 내역 유지
$ git revert <취소할커밋>

시간을 되돌린 것처럼 특정 커밋으로 되돌아감 -> 없던 일 처리
soft reset : 커밋을 했다는 그 사실만을 되돌리기
$ git reset --soft <되돌아갈 커밋>

mixed reset : 스테이지에 추가했다는 사실까지 되돌리기
$ git reset [--mixed] <되돌아갈 커밋>

hard reset : 변경사항을 만들었다는 사실까지 되돌리기
$ git reset --hard <되돌아갈 커밋>
  • 브랜치로 나누어 관리하기(☆★필수!!)
새로운 브랜치 생성하기
$ git branch <브랜치이름>

해당 브랜치로 체크아웃하기 -> 해당 브랜치로 go!
$ git checkout <브랜치이름>

새로운 브랜치를 만들고 동시에 체크아웃하기
$ git checkout -b <브랜치이름>

브랜치 병합하기
$ git merge <브랜치이름>

충돌 해결법 -> 최종적으로 포함할 내용을 직접 선택 후 다시 커밋(어떤 것을 따라갈 지)
  • 원격저장소(깃허브) 다루기
원격 저장소 이름 조회하기
$ git remote

원격 저장소 이름 + url 조회하기
$ git remote -v

원격 저장소 추가하기
$ git remote add <원격저장소이름> <원격저장소경로>
  • 원격저장소와 상호작용
clone: 원격 저장소의 내용을 내 컴퓨터로 복제해오기
$ git clone <원격저장소경로>

push: 로컬의 변경사항을 원격저장소로 밀어넣기
$ git push <원격저장소이름> <로컬브랜치이름>

fetch: 원격저장소의 변경사항을 로컬로 '일단 갖고만' 오기 -> 내가 작업하고 있는 브랜치는 건들이지 않음
$ git fetch <원격저장소이름> <로컬브랜치이름>

pull: 원격저장소의 변경사항을 로컬로 갖고와서 합치기
$ git pull <원격저장소이름> <로컬브랜치이름>
  • Pull Request로 협업하기
1. 기여하려는 저장소를 본인의 계정으로 fork 하기
2. fork한 저장소를 clone하기
3. 브랜치 생성 후 생성한 브랜치에서 작업하기
4. 작업한 브랜치 Push 하기
5. Pull Request 보내기
  • Pull Request 협업 : 기여하려는 저장소를 본인 계정 저장소(깃허브)에 fork하기 -> 내 깃헙을 내 컴퓨터로 clone하기 -> 브랜치 생성 후 작업(branch, add, commit)-> (중간중간 원격저장소 내용 fetch, pull) -> 작업한 브랜치 push -> pull request 보내기
  • 내 작업 내 github에 올리기 : git init(로컬 저장소) -> 깃헙에 저장소 생성 -> 원격 저장소 추가(remote add) -> 브랜치에서 작업하기(branch, add, commit, merge) -> 내 깃헙에 push

 

 

2. 파이썬 특강

  • class : 선언 후 바로 사용되는 함수와 달리 인스턴스를 생성해 사용
    - class 내부 선언 메소드는 기본적으로 self 인자를 가짐(메소드 선언 시 항상 첫번째 인자)
    - self : 클래스 내에서 전역 변수처럼 사용
  • class 기본 구조
class CookieFrame():  # CookieFrame class 선언
	def set_cookie_name(self, name):  # class 내부 method는 첫번째 인자로 self
    	self.name = name
       
cookie1 = CookieFrame()  # cookie1 인스턴스 생성
cookie2 = CookieFrame()  # cookie2 인스턴스 생성

cookie1.set_cookie_name("cookie1")  # method의 첫번째 인자 self가 아닌 두번째 인자 name에 전달
cookie2.set_cookie_name("cookie2")

print(cookie1.name)  # cookie1
print(cookie2.name)  # cookie2
  • __init__ 함수 : 인스턴스 생성 시 가장 먼저 실행되는 메소드
class CookieFrame():
	def __init__(self, name):
    	print(f"생성 된 과자의 이름은 {name} 입니다!")
        self.name = name
        
cookie1 = CookieFrame("cookie1")  # 생성 된 과자의 이름은 cookie1 입니다!
cookie2 = CookieFrame("cookie2")  # 생성 된 과자의 이름은 cookie1 입니다!
  • class 예시
from pprint import pprint  # 예쁘게 출력

class Profile:  # Profile class 선언
    def __init__(self):  # 초기화 -> 인스턴스 생성 시 가장 먼저 실행
        self.profile = {  # profile 초기화
            "name": "-",
            "gender": "-",
            "birthday": "-",
            "age": "-",
            "phone": "-",
            "email": "-",
        }
    
    def set_profile(self, profile):  # self_profile 메소드 : profile 내용 설정
        self.profile = profile
        
    def get_profile(self):  # get_profile 메소드 : profile 내용 반환
        return self.profile
    
profile1 = Profile()  # 인스턴스 생성
profile2 = Profile()

profile1.set_profile({
    "name": "lee",
    "gender": "man",
    "birthday": "01/01",
    "age": 32,
    "phone": "01012341234",
    "email": "python@sparta.com",
})

profile2.set_profile({
    "name": "park",
    "gender": "woman",
    "birthday": "12/31",
    "age": 26,
    "phone": "01043214321",
    "email": "flask@sparta.com",
})

pprint(profile1.get_profile())
pprint(profile2.get_profile())

# result print
"""
{   
    'name': 'lee',
    'gender': 'man',
    'birthday': '01/01',
    'age': 32,
    'phone': '01012341234',
    'email': 'python@sparta.com'
}
{
    'name': 'park',
    'gender': 'woman',
    'birthday': '12/31',
    'age': 26,
    'phone': '01043214321',
    'email': 'flask@sparta.com'
}
"""
  • mutable 자료형 : 값이 변한다 -> list, dict
  • immutable 자료형 : 값이 변하지 않는다 -> int, float, str, tuple
  • mutable VS immutable
immutable = "String is immutable!!"
mutable = ["list is mutable!!"]
 
string = immutable
list_ = mutable  # mutable은 주소를 가리킨다고 생각!!

string += " immutable string!!"  # 값이 변경되면서 메모리 주소값도 달리진다!!
list_.append("mutable list!!")

print(immutable)
print(mutable)
print(string)
print(list_)

# result print
"""
String is immutable!!
['list is mutable!!', 'mutable list!!']
String is immutable!! immutable string!!
['list is mutable!!', 'mutable list!!']
"""

 

 

3. 백준(크로아티아, 그룹단어 체커)

str = input()
#str = list(input())
count = len(str)

#예외 상황
cro_al = ['c=','c-','dz=','d-','lj','nj','s=','z=']

for i in range(0, len(str)):
    if len(str) < 2:  #입력문자열이 1글자이면 무조건 크로아티아 알파벳이 아님
        count = len(str)
    elif len(str) == 2: #입력문자열이 2글자인 경우
        if (str[i-2] + str[i-1]) in cro_al: #해당 두 글자가 크로아티아 알파벳인 경우, c=
            count = 1
    elif (str[i-3] + str[i-2] + str[i-1]) in cro_al:  #3글자 이상이면서 크로아티아 알파벳(3개)인 경우, dz=
        count -= 2
    elif (str[i-2] + str[i-1]) in cro_al: #3글자 이상이면서 크로아티아 알파벳(2개)인 경우, c-
        count -= 1

print(count)
#i = 0
#while i < len(str):
#    if str[i] == 'c':
#        if str[i+1] == '=' or str[i+1] == '-':
#            count -= 1
#            i += 2
#        else:
#            i += 1
#    elif str[i] == 'd':
#        if str[i+1] == '-':
#            count -= 1
#            i += 2
#        elif str[i+1] == 'z' and str[i+2] == '=':
#            count -= 2
#            i += 3
#        else:
#            i += 1
#    elif str[i] == 'l':
#        if str[i+1] == 'j':
#            count -= 1
#            i += 2
#        else:
#            i += 1
#    elif str[i] == 'n':
#        if str[i+1] == 'j':
#            count -= 1
#            i += 2
#        else:
#            i += 1
'''    elif str[i] == 's':
        if str[i+1] == '=':
            count -= 1
            i += 2
        else:
            i += 1
    elif str[i] == 'z':
        if str[i+1] == '=':
            count -= 1
            i += 2
        else:
            i += 1
    else:
        i += 1

print(count)
'''

n = int(input())
cnt = n
#입력을 라인별로 받기 때문에 리스트 불필요
#arr = []

# n개의 단어 입력받기
for i in range(n):
    word = input()  #라인 별로 단어를 입력받아
    #arr.append(input())
    for j in range(0, len(word)-1): #단어의 각 글자를 확인
        if word[j] == word[j+1]: #해당 글자가 다음 글자와 같으면 다음 글자로 넘어감
            pass
        elif word[j] in word[j+1:]: #해당 글자가 다음 글자와 같지 않고, 뒷부분에 존재하면 cnt에서 하나씩 차감
            cnt -= 1
            break

print(cnt)            

#for i in range(n):
#    a = list(i)  [h, a, p, p, y]  [a, b, a]
#    for j in range(len(a)):
#        if(a.count(a[j]) > 1):

 

 

4. 후기

오늘은 꾸준하게 할 일을 다했다... 코드 깨끗하게.. 알고리즘 어렵다;;; 파이썬 클래스 내용, 깃헙 사용법 정리 잘했다...

반응형