💬 Programming Language/Python

저 두개는 vsc에서 그냥 print()로 찍어보면 똑같게 나온다. 그래서 주피터로 해봄 후자의 장점은 저렇게 씀으로서 저 리스트 덩어리를 문자열 하나로 볼 수 있음. 문자 개수세기 문제에서 활용 가능 #1~10000에서 숫자 8이 등장하는 개수 세기(8808은 +3개) # 방법1 print(str(list(range(1, 10001))).count('8')) # 방법2 count = 0 for i in range(1, 10001): if '8' in str(i): count += str(i).count('8') print(count) # 방법3 print(str([i for i in range(1, 10001)]).count('8'))
Global Variable 사용하기알고리즘 문제를 풀다가 발견한.. function안에서 global variable사용하는 방법나는 쓸 생각도 못했던거라 한번 정리해두고 넘어가면 다음에 쓰겠지 싶어서 정리해본다.전역변수가 무엇인지 어떻게 쓰는지는 저 아래 코드와 w3schools의 글을 참고하면 되니까따로 정리하진 않을거고 어떻게 문제에서 썼는지만 간략히 기록해볼려고 한다.def turn_left(): global direction direction -= 1 if direction == -1: direction = 3방향설정->이동 문제유형에서 방향전환 기능 구현을 위해 함수를 만듦방향에 따른 이동량은 dx, dy라는 두 개의 리스트를 만들어서 관리함각 direction에..
Q3: Insect CombinatoricsConsider an insect in an M by N grid. The insect starts at the bottom left corner, (1, 1), and wants to end up at the top right corner, (M, N). The insect is only capable of moving right or up. Write a function paths that takes a grid length and width and returns the number of different paths the insect can take from the start to the goal. (There is a closed-form solution..
녕 지
'💬 Programming Language/Python' 카테고리의 글 목록