본문 바로가기
  • 머킹이의 머신로그
오늘부터 코딩테스트

[오늘부터 코딩테스트]파이썬으로 프로그래머스 코딩 기초 프로그램 풀기

by 머킹 2023. 11. 8.
728x90

[파이썬] 프로그래머스 Lv0. 문자열을 정수로 변환하기, 0 떼기

 

안녕하세요 머킹입니다!

ModuleNotFoundError: No module named 'autogpt'라는 오류에 몇 번째 부딪치고 있는데...

from diffusers import UNet2DModel
from autogpt.config import Config

model = UNet2DModel(
    sample_size=config.image_size,  # the target image resolution
    in_channels=3,  # the number of input channels, 3 for RGB images
    out_channels=3,  # the number of output channels
    layers_per_block=2,  # how many ResNet layers to use per UNet block
    block_out_channels=(128, 128, 256, 256, 512, 512),  # the number of output channes for each UNet block
    down_block_types=(
        "DownBlock2D",  # a regular ResNet downsampling block
        "DownBlock2D",
        "DownBlock2D",
        "DownBlock2D",
        "AttnDownBlock2D",  # a ResNet downsampling block with spatial self-attention
        "DownBlock2D",
    ),
    up_block_types=(
        "UpBlock2D",  # a regular ResNet upsampling block
        "AttnUpBlock2D",  # a ResNet upsampling block with spatial self-attention
        "UpBlock2D",
        "UpBlock2D",
        "UpBlock2D",
        "UpBlock2D"
      ),
)

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[3], line 2
      1 from diffusers import UNet2DModel
----> 2 from autogpt.config import Config
      4 model = UNet2DModel(
      5     sample_size=config.image_size,  # the target image resolution
      6     in_channels=3,  # the number of input channels, 3 for RGB images
   (...)
     25       ),
     26 )

 

정말... 미치겠네요 ㅎ

마음 같아서는 코랩 유료 결제 하고 싶어요.

 


문자열을 정수로 변환하기

 

문제 설명

숫자로만 이루어진 문자열 n_str이 주어질 때, n_str을 정수로 변환하여 return 하도록 solution 함수를 완성해 주세요.

 

def solution(n_str):
    return int(n_str)

이렇게 풀었습니다!

 

solution = int

근데 너무 놀라운... 답을 발견했어요 ㅋㅋㅋㅋㅋ

 


0 떼기

 

문제 설명

정수로 이루어진 문자열 n_str이 주어질 때, n_str의 가장 왼쪽에 처음으로 등장하는 0들을 뗀 문자열을 return 하도록 solution 함수를 완성해 주세요.

def solution(n_str):
    return n_str.lstrip("0")
def solution(n_str):
    return str(int(n_str))

이런 풀이도 있어요.

되게 창의적이네요.