
이 글은 이것이 취업을 위한 코딩테스트다 APPENDIX A
코딩테스트를 위한 파이썬 문법파트를 읽고 정리한 글입니다.
APPENDIX A에 수록된 문법 외에 개인적으로 알고리즘 문제를 풀다가 막힌 문법들 또한 추가해두었으며, 예제는 직접 연습하며 작성하였기에 교재랑 다른 부분이 있습니다.
>>> round(실수형 데이터, 반올림하고자하는 위치-1)
>>> round(123.456, 2)
123.46
>>> a=0.3+0.6
>>> a
0.8999999999999999
>>> round(a, 4)
0.9
>>> list = [0]*10
>>> list
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
파이썬 컴프리헨션 정리(list, set, dictionary) (python comprehension에 대하여 자세하게 정리해 두었으니 필요하신 분들은 확인하셔요🥰)
🌟 보통의 리스트 컴프리헨션에서는 조건문이 뒤에 오지만,
[<the_expression> for <the_element> in <the_iterable> if <the_condition>]
if ~ else 구문에서는 if 조건식이 for 반복문 앞에 위치한다. [<the_expression> if <the_condition> else <other_expression> for <the_element> in <the_iterable>]
N*M 크기의 2차원 리스트 초기화
n = 4
m = 3
array = [[0]*m for _ in range(n)]
array
[[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]
for x in array:
    for y in x:
        print(y, end=" ")
    print()
※ 개인적으로는 2차원 리스트를 출력할 때 위와 같은 방법을 사용하는데 더 좋은 방법이 있다면 알려주세요😉
| 사용법 | 설명 | 시간복잡도 | 
|---|---|---|
| 변수명.append() | 리스트에 원소 삽입 | |
| 변수명.sort() | 오름차순으로 정렬 | |
| 변수명.sort(reverse=True) | 내림차순으로 정렬 | |
| 변수명.reverse() | 원래 원소의 순서를 뒤집어 놓음 | |
| 변수명.insert(인덱스, 삽입할 값) | 지정한 위치에 원소 삽입 | |
| 변수명.count(특정 값) | 특정한 값을 가지는 데이터의 개수 | |
| 변수명.remove(특정 값) | 특정한 값을 갖는 원소 제거 | 
시간 초과가 뜰 수 있다.>>> data = [1, 2, 1, 6, 6, 6]
>>> remove_set = {2, 6}
>>> result = [x for x in data if x not in remove_set]
>>> result
[1, 1]
예시1) append(), sort()
>>> list=[2, 8, 4, 1]
>>> list.append(0)
>>> list
[2, 8, 4, 1, 0]
>>> list.sort()
>>> list
[0, 1, 2, 4, 8]
>>> list.sort(reverse = True)
>>> list
[8, 4, 2, 1, 0]
예시2) reverse()
>>> list
[8, 4, 2, 1, 0, 7]
>>> list.reverse()
>>> list
[7, 0, 1, 2, 4, 8]
예시3) insert()
>>> list.insert(0, 9)
>>> list
[9, 7, 0, 1, 2, 4, 8]
예시4) count()
>>> list.append(9)
>>> list
[9, 7, 0, 1, 2, 4, 8, 9]
>>> list.count(9)
2
예시5) remove()
>>> list.remove(0)
>>> list
[9, 7, 1, 2, 4, 8, 9]
이 시리즈가 코딩테스트를 공부하시는데 조금이나마 도움이 되었다면 💚를 눌러주세요😉
Working with JPA Repository Grammar can feel a bit technical, but it’s all about combining pieces in the right way to get the outcome you want. I like to think of it like using a picture collage maker online you pull different elements together, arrange them properly, and end up with something clean and meaningful. Once you get the hang of the structure, the whole process becomes much more intuitive.
안녕하세요! 피드의 몇몇 게시글들은 봤는데 프론트엔드 개발자가 목표이신가요? 혹시 프론트엔드 개발자가 목표시라면 코테를 파이썬으로 준비하시는 이유가 있나요?