예사로운
close
프로필 배경
프로필 로고

예사로운

  • 분류 전체보기
    • Python
      • Python
      • Django
    • Algorithms and Data Structu..
      • Algorithms
    • JavaScript
      • JavaScript
      • React
      • jQuery
    • CS
      • Web
      • HTML CSS
    • SQL
      • Oracle
    • Java
      • Java
      • JDBC
    • Git
    glob.glob() 함수

    glob.glob() 함수

    glob.glob() 함수는 파라미터로 받은 패턴과 이름이 일치하는 모든 파일과 디렉터리를 리스트로 반환합니다. import glob glob.glob(pattern) 파라미터인 pattern에는 아래와 같은 특수문자가 포함될 수 있습니다. * : 0개 이상의 임의 개수의 문자와 일치합니다. 그래서 glob.glob(*) 이 경우는 모든 파일과 디렉터리를 볼 수 있습니다. ? : 정확히 하나의 문자와 일치합니다. [] : 괄호 안의 단일 문자와 일치합니다. [!] 또는 [^] : 대괄호 안에 없는 단일 문자와 일치합니다. {} : 중괄호 안의 쉼표로 구분된 패턴과 일치합니다. . : 리터럴 점(.)과 일치합니다. 예시 import glob # 1) 현재 디렉터리에 있는 모든 파일과 디렉터리 files =..

    • format_list_bulleted Python/Python
    • · 2023. 6. 11.
    • textsms
    Python 라이브러리 - functools

    Python 라이브러리 - functools

    functools 공식 문서 링크 source code 링크 functools.cmp_to_key functools.cmp_to_key(func)는 sorted()와 같은 정렬 함수의 key 매개변수에 함수(func)를 전달할 때 사용하는 함수입니다. 단, func() 함수는 두 개의 인수를 입력해 첫 번째 인수를 기준으로 그 둘을 비교하고 작으면 음수, 같으면 0, 크면 양수를 반환하는 비교 함수이어야 합니다. 예시 2차원 평면 위의 점 N개를 (x, y) 좌표로 구성한 리스트가 있고 이 리스트를 y 좌표가 증가하는 순으로 정렬하되 y 좌표가 같으면 x좌표가 증가하는 순으로 정렬하를 프로그램입니다. import functools def xy_compare(n1: int, n2: int) -> int: ..

    • format_list_bulleted Python/Python
    • · 2023. 5. 24.
    • textsms
    Python 라이브러리 - itertools

    Python 라이브러리 - itertools

    공식 문서 링크 source code 링크 itertools.cycle itertools.cycle은 반복 가능한 객체(iterable)를 순서대로 무한히 반복하는 이터레이터를 생성하는 함수입니다. 예시 import itertools emp_pool = itertools.cycle(['kim', 'lee', 'park']) print(next(emp_pool)) # kim print(next(emp_pool)) # lee print(next(emp_pool)) # park print(next(emp_pool)) # kim 참고로 next()는 python 내장 함수로, 이터레이터의 다음 요소를 반환하는 함수입니다. itertools.accumulate itertools.accumulate는 반복 가능한 ..

    • format_list_bulleted Python/Python
    • · 2023. 5. 20.
    • textsms
    Python 라이브러리 - operator.itemgetter

    Python 라이브러리 - operator.itemgetter

    공식 문서 링크 source code 링크 operator.itemgetter operator.itemgetter는 주로 sorted와 같은 함수의 key 매개변수에 적용하여 다양한 기준으로 정렬할 수 있도록 하는 모듈입니다. 예시 이름, 나이, 성적이 있는 학생 데이터를 기준에 맞게 정렬하는 프로그램입니다. tuple(나이 기준) from operator import itemgetter students = [ ("kim", 23, "A"), ("park", 12, "C"), ("lee", 19, "B"), ] result = sorted(students, key=itemgetter(1)) print(result) # [('park', 12, 'C'), ('lee', 19, 'B'), ('kim', 23..

    • format_list_bulleted Python/Python
    • · 2023. 5. 18.
    • textsms
    Python 라이브러리 - statistics

    Python 라이브러리 - statistics

    공식 문서 source code 링크 statistics statistics는 평균값과 중앙값을 구할 때 사용하는 모듈입니다. 평균값은 statistics.mean() 함수를 사용하면 간단하게 구할 수 있습니다. import statistics mark = [79, 29, 40, 69, 90, 100, 74, 69] print(statistics.mean(mark)) # 68.75 중앙값은 statistics.median() 함수를 사용해 구하면 됩니다. print(statistics.median(mark)) # 71.5 http://www.yes24.com/Product/Goods/109209932 Do it! 점프 투 파이썬 라이브러리 예제 편 - YES24 『Do it! 점프 투 파이썬』의 후속 편..

    • format_list_bulleted Python/Python
    • · 2023. 5. 17.
    • textsms
    Python 라이브러리 - random

    Python 라이브러리 - random

    공식 문서 source code 링크 random random은 난수를 생성할 때 사용하는 모듈입니다. 아래는 1 ~ 45 사이 숫자 중 임의의 숫자를 생성하는 예시 코드입니다. import random result = [] while len(result) < 6: num = random.randint(1, 45) # 1 ~ 45 사이의 정수 생성 if num not in result: # 중복 숫자 방지 result.append(num) print(result) # [7, 20, 21, 25, 45, 43] random.randint(a, b)는 a와 b사이의 무작위 정수를 생성하는 함수입니다. shuffle과 choice shuffle 리스트 요소를 무작위로 섞고 싶다면 random.shuffle()..

    • format_list_bulleted Python/Python
    • · 2023. 5. 17.
    • textsms
    • navigate_before
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • navigate_next
    공지사항
    전체 카테고리
    • 분류 전체보기
      • Python
        • Python
        • Django
      • Algorithms and Data Structu..
        • Algorithms
      • JavaScript
        • JavaScript
        • React
        • jQuery
      • CS
        • Web
        • HTML CSS
      • SQL
        • Oracle
      • Java
        • Java
        • JDBC
      • Git
    최근 글
    인기 글
    최근 댓글
    태그
    • #오라클
    • #java
    • #Django
    • #SQL
    • #oracle
    • #git
    • #CSS
    • #Python
    • #JavaScript
    • #HTML
    전체 방문자
    오늘
    어제
    전체
    Copyright © 쭈미로운 생활 All rights reserved.
    Designed by JJuum

    티스토리툴바