목록Python (6)
Kim Jinung
functools — Higher-order functions and operations on callable objects Source code: Lib/functools.py The functools module is for higher-order functions: functions that act on or return other functions. In general, any callable object can be treated as a function for t... docs.python.org Reduce 함수는 이터러블한 객체의 두 인자에, 함수를 누적 해서 적용할 때 사용할 수 있는 함수다. 리스트 [1, 2, 3]이 있을 때 두 인자에 덧셈이라는 함수를 누적 해서 적용하면 1 + 2 ..
heapq — Heap queue algorithm — Python 3.11.1 documentation heapq — Heap queue algorithm Source code: Lib/heapq.py This module provides an implementation of the heap queue algorithm, also known as the priority queue algorithm. Heaps are binary trees for which every parent node has a value less than or equal to an docs.python.org heapq 모듈은 heap queue 알고리즘의 구현을 제공한다. (우선순위 큐 알고리즘으로도 알려져있다.) *주의할 점은..
collections — Container datatypes — Python 3.11.0 documentation collections — Container datatypes Source code: Lib/collections/__init__.py This module implements specialized container datatypes providing alternatives to Python’s general purpose built-in containers, dict, list, set, and tuple. namedtuple() factory f docs.python.org Counter 클래스는 Dictionary의 subclass로 hashable한 객체를 카운팅할 때 사용할 수 있다...
4. More Control Flow Tools — Python 3.11.0 documentation 4. More Control Flow Tools Besides the while statement just introduced, Python uses the usual flow control statements known from other languages, with some twists. 4.1. if Statements Perhaps the most well-known statement type is the if statement. For examp docs.python.org for loop 순회 중 특정 조건을 찾고 break를 걸어야하는 일이 있다. 그리고 break 조건에 해당하는 케이스를 ..
re — Regular expression operations — Python 3.11.0 documentation re — Regular expression operations Source code: Lib/re/ This module provides regular expression matching operations similar to those found in Perl. Both patterns and strings to be searched can be Unicode strings (str) as well as 8-bit strings (bytes). Ho docs.python.org Regex(Regular Expression)은 텍스트에서 패턴을 찾아내어 복잡한 문자열 처리에 사용하는 기법이..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/dosaGi/btrRPCgrlnU/C97qcrxHxfrTfdfQPo8CIk/img.png)
파이썬의 리스트, 딕셔너리, 스트링 같이 원소를 가지는 데이터 구조를 컨테이너라고 부른다. 그리고 컨테이너는 이터레이블하며 이는 반복이 가능한, 순회가 가능한 자료구조라는 의미다. 그리고 이터레이블한 객체는 이터레이터라는 인스턴스를 생성할 수 있다. num_list = [1, 2, 3] for num in num_list: print(num) num_list는 리스트라는 컨테이너다. 따라서 이터레이블하다. for 문에서는 이터레이블한 num_list를 순회하고자 한다. 이때 num_list를 그대로 사용하는 것이 아니라 num_list를 활용해서 이터레이터 인스턴스를 생성한다. 이터레이터는 값 생성기로 다음 값을 요청하면 반환하고 그 다음 값을 반환하게 된다. 위 for 문에서 num 변수는 처음 1을 ..