Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 컨테이너
- mysql
- paramiko
- SSH
- 기타 연주
- windows forms
- label
- 프로그래머스
- C
- Linux
- VS Code
- 오류
- LIST
- Numpy
- YOLO
- 채보
- Docker
- OpenCV
- 핑거스타일
- C++
- JSON
- pytorch
- Visual Studio
- ubuntu
- pip
- Python
- Selenium
- error
- C#
- pandas
Archives
- Today
- Total
목록여러 줄 문자열 (1)
기계는 거짓말하지 않는다
Python 여러 줄 문자열 각 라인 최소 indent 만큼 제거하고 출력
Python에서 """로 선언된 여러 줄 문자열의 각 라인 최소 indent 만큼 제거하고 출력하는 방법이다. 각 라인의 맨 앞 indent 중 최소를 찾아 앞으로 붙여 정렬한다. def adjust_indent(text: str) -> str: lines = text.split('\n') # 각 라인에서 공백 제외 부분의 길이를 찾아 최소 길이 계산 min_indent = min(len(line) - len(line.lstrip()) for line in lines if line.strip()) # 각 라인을 최소 indent만큼 제거하고 출력 adjusted_lines = [line[min_indent:] if line.strip() else line for line in lines] return '..
Python
2024. 1. 1. 18:53