Python5 [LeetCode 3] Longest Substring Without Repeating Characters 풀이 문제 : 단어 변수 s를 받고 반복되지 않는 글자 수의 최댓값 return 하기 예시 : "abcabcbb" 에서 "abc" 가 중복되지 않으면서 글자수가 가장 김. 따라서 답은 3 풀이 : 변수 초기값 설정한다. used : 사용한 알파벳과 위치를 저장하기 위한 빈 dictionary max_length : 최대 단어 길이 start : 단어 길이를 재기 위한 시작 위치 used = {} max_length = start = 0 단어를 loop에 넣는다. 알파벳 길이를 쉽게 알기 위해 enumerate를 씌운다. for idx, c in enumerate(s): 아래 코드부터는 모두 loop 안에 들어간다. 딕셔너리에 순번인 알파벳(c)이 들어있고, 그 알파벳의 기존 위치가 start 변수 값보다 크면.. 2022. 12. 27. [Python] directory [현재 경로] direct = os.getcwd() [폴더 만들기] answer = './results' if os.path.exists(answer): pass else: os.mkdir(answer) [경로 안 파일 리스트] DirectoryFiles = os.listdir(answer) for oneFile in DirectoryFiles : filePath = os.path.join(answer, oneFile) 2022. 6. 3. [Python] 파일압축 및 압축풀기 [압축] import shutil shutil.make_archive(저장 경로 및 파일명, 'zip', 압축할 파일경로) ex) shutil.make_archive('./zip_results', 'zip', './results/') [압축해제] dir_zip = '/home/datasets/test.zip' dir_extract = '/home/datasets/test' import zipfile with zipfile.ZipFile(dir_zip, 'r') as zip_ref: zip_ref.extractall(dir_extract) 2022. 6. 2. [Python] GPU 제한 [ TF ] gpu 제한 명령어 gpu = tf.config.experimental.list_physical_devices('GPU') if gpu: tf.config.experimental.set_virtual_device_configuration(gpu[0], [tf.config.experimental.VirtualDeviceConfiguration(memory_limit = 7 * 1024)]) 2022. 4. 15. [Linux] 파일 돌리기 보호되어 있는 글 입니다. 2022. 2. 14. 이전 1 다음