Giter Site home page Giter Site logo

algorithm_study's Introduction

Algorithm_study

sort 함수는 리스트.sort() 형식으로 사용되며 리스트의 원본값을 직접 수정 -> 메소드
sorted 함수는 sorted(리스트) 형식으로 사용되며 정렬 값을 반환 -> 파이썬 내장 함수
아스테리크 (*) 사용법
a = [1,2,3,4]
1.
-> print(*a) 할 시 1 2 3 4 와 같이 출력 됨(리스트에서 요소가 떨어저 나옴)
-> print(*a,sep='\n')와 같은 식으로 응용 가능 -> 1,2,3,4가 종으로 출력 / sep = '\n'는 출력하는 값 사이에 특정한 문자를 추가하여 출력함
2.
-> *x, y = a 일 시 x = [1, 2, 3]가 y = 4가 저장됨
-> x,*y, z = a 일 시 x = 1, y = [2, 3], z = 4가 저장됨
set 함수를 사용하여 집합 형으로 바꾼 리스트들은 연산이 가능하다 -> 함수랑 똑같음
리스트를 빈 리스트로 초기화 하려면 리스트.clear() 메소드를 사용
한줄 for 문 사용법
-> [i for i in range(3)] 은 [0, 1, 2]를 반환함
-> [i for i in range(n) 조건문]과 같이 사용 가능
sort 메소드 사용법
-> 리스트.sort()는 리스트를 오름차순으로 정렬함 / 리스트.sort(reverse=True)는 내림차순으로 정렬함
-> 리스트.sort(key=len)은 리스트를 길이 순으로 정렬함
-> sorted() 함수는 정렬 값을 반환함
-> sort와 sorted 함수 모두 정렬을 목적으로하는 함수를 key 값으로 설정할 수 있음, 람다 함수 사용 가능
-> sorted(문자열)은 각 문자들을 요소로하는 리스트를 생성 가능 list(문자열)과 비슷함
-> a = 'aaedaee'일때 sorted(a,key=a.find)를 사용하면 알파벳의 아스키 순서대로 정렬되지 않고 먼저 온 알파벳 순서대로 정렬됨 ...
-> 문자열 처리 된 정수를 정렬하면 앞자리 수 기준으로 정렬 됨, 문자는 맨 앞의 단어 파닉스 기준
문자열 간단하게 뒤집는 법
a = 'abcdef'
print(a[::-1]) # fedcba를 출력
for 문에서 range() 값에 0을 집어넣으면 for 문을 실행하지 않고, 오류 또한 발생하지 않음
input() 과 sys.stdin.readline()의 차이점
-> input() 함수는 입력을 받기 전 입력을 받기위한 prompt를 가짐 -> 대량의 입력을 받는 경우 오류가 발생할 수 있음
-> input() 함수는 입력을 받고 개행문자를 제거하여 반환함, but sys~는 개행문자를 포함함(개행문자를 입력안해도)
-> print() 함수도 sys 꼴로 사용할 수 있는데 -> sys.stdout.write() 정수는 못 읽는 듯하다 -> 요놈은 print()와 다르게 개행 문자가 없다
람다 함수 정리
ex) (lambda x,y: x+y)(1,2) -> 3을 반환 (왼쪽이 파라미터, 오른쪽이 반환 값을 나타냄
람다 함수는 이중 리스트의 정렬에도 사용 가능 a라는 리스트가 있을 때
sorted(a, key = lambda a : a[1],a[0]) 이라면 첫번째 요소의 인덱스 1을 첫번째 기준으로, 인덱스 0을 두번째 기준으로 정렬함

for i in range(3):
    print(i)

algorithm_study's People

Contributors

jhyeun1020 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.