냥냥's 2021. 9. 17. 01:33

첫 시작 TIL 내가 과연 잘 할 수 있을까

오늘은 파이썬 for 구문에 하면서 새로운 방법을 알아냈다.

List가 있으면

for a in List 라고 하면 List의 내용을 하나하나 a라는 변수에 담아간다

@app.route('/sort', methods=['POST'])
def sort_campings():
    location_receive = request.form['sortlocation']
    camp_dataS = list(db.camp_info.find({},{'_id':False}))
    sorted_data = []

    for camp in camp_dataS:
        if location_receive in camp['location']:
            sorted_data.append(camp)
        if location_receive == '전체':
            sorted_data = camp_dataS

    print(sorted_data)
    return jsonify({'sorted_data': sorted_data})

db에서 받아와서 조회수로 내림차순 정렬하는 거였는데 나는 딕셔너리 자체에서 정렬하는 방법을 생각 못해서 위에 처럼 짰지만 같은 조장분은  b_sort_by_val = dict(sorted(b.items(), key=lambda x: x[1], reverse=True))딕셔너리 키로 정렬 하는 방법으로 하셨다.

자료구조를 이해하는 수준이 다른 것 같다고 느꼈다ㄹㄴㅇㄻㅇㄹㅇ이거ㅇ

[출처] [파이썬] 딕셔너리 키, 값으로 정렬 (Sort Dictionary by Key or Value) / 오름차순, 내림차순 정렬|작성자 somsom

# 캠핑 목록 소팅(POST) - 리뷰수
@app.route('/sort_order', methods=['POST'])
def sort_view():
    order_receive = request.form['order']
    camps = list(db.camp_info.find({}, {'_id': False}))
    sort_order = []

    for camp in camps:
        camp['view'] = int(camp['view'])
    
    if order_receive == 'descending':
        sort_order = sorted(camps, key=(lambda x: x['view']), reverse=True)
        for x in sort_order:
            print(x)

    return jsonify({'sort_order': sort_order})

하면 이렇게 된다.

 

그리고 오늘 GitGub에 대해 공부하였다

 

 

git status      //현재 로컬저장소의 상태를 본다

git add 파일이름   //파일 스테이지(임시저장소)에 올리기

git commit -m "입력메세지"  //파일코밋하기
단, 입력메세지는 대문자 동사형태
ex> Add login func
Add
Fix
Simplify
Refector

git push origin shinsw627 파일푸쉬하기(github에 넣는다)
git push 원격저장소이름 브랜치이름


git checkout -t origin/kzhxxn kzhxxn이라는 브랜치 복사해서 로컬에 동일한브랜치 생성


git add "파일명" //파일명 스테이지에 더하기

git commit -m "메세지" //스테이지에 있는 파일 commit

git restore --staged '파일명'  //스테이지에 있는 파일 빼기





git config --global user.email email@naver.com

git config --global user.name name

git init // 디렉토리에 Git 저장소 생성

git status // 현재 상태 확인

git add -A // 변경된 내용 일체 추가

git commit -m "first commit" // 코멘트 달아서 로컬저장소 업데이트

git log // 이력 확인

git reset {커밋 아이디} --hard // 이전 상태로 이력제거 (커밋 아이디 = 306b9474...)

git revert {커밋 아이디} // 이전 상태로 이력 유지

git switch Test // Test 브랜치로 이동

git switch -c Test // main 브랜치에서 Test 브랜치를 생성하여 이동

git branch Test // main 브랜치에서 Test 브랜치를 생성

git branch -D Test // Test 브랜치 삭제하기

git merge Test // main 브랜치에서 수행할 것. Test 수정사항을 main 브랜치로 머지

git remote add origin https://github.com/Test1/Test2.git

git push -u origin main // 현재 브랜치를 origin/main 브랜치로 푸시

git clone https://github.com/Test1/Test2.git Test // 원격 저장소로부터 복제하여 Test 브랜치 생성

git checkout -t origin/Test // 원격저장소로부터 복제하여 로컬저장소에 동일한 브랜치 생성  

git pull // 원격저장소에서 로컬저장소로 가져오기

git branch --set-upstream-to=Test1/Test2 Test2 // 원격저장소 Test2를 로컬저장소 Test2와 연결하기

*[출처] [Git] 깃허브 관련 명령어 모음|작성자 오늘하루어쩐지*

rm -rf 파일명 //해당 파일 삭제

git push --set-upstream origin 아이디 // upstream 셋팅

썼었던 명령어 전부 기록하다 보니 약간의 중복도 있지만 전체적인 흐름은 이해한 거 같다.

변경을 기준으로 관리한다는게 너무 신기하다; 원리는 어떻게 되는거지;;

 

나중에 관련서적 읽어야겠다

그리고 자료구조! 알고리즘! 서적도 읽어라