Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STEP 4. 1차원 배열 #5

Open
10 tasks done
letsjo opened this issue Mar 29, 2023 · 0 comments
Open
10 tasks done

STEP 4. 1차원 배열 #5

letsjo opened this issue Mar 29, 2023 · 0 comments
Assignees
Labels
STEP 단계

Comments

@letsjo
Copy link
Owner

letsjo commented Mar 29, 2023

단계 설명

배열을 사용해 봅시다.

문제 / 코드보기

새로 알게된 점

  • lines = sys.stdin.readlines() 의 반환값은?

     import sys
     # 1
     # 2
     # 3
     numbers = list(map(int,sys.stdin.readlines()))
     # print(numbers)  # [1, 2, 3]
    
     lines = sys.stdin.readlines()
     # print(lines) # ['1\n', '2\n', '3\n']
     numbers = list(map(lambda s: s.strip(), lines))
     # print(numbers)  # ['1', '2', '3']
     numbers = list(map(lambda s: int(s.strip()), lines))
     # print(numbers)  # [1, 2, 3]
  • List index 찾는 방법?

     numbers = [3,2,1]
     print(numbers.index(3)) 	// 0
     print(numbers.index(2)) 	// 1
     print(numbers.index(1)) 	// 2
  • List 값 채우기

     baskets = ['0' for i in range(N)] # N개 원소를 가진 배열에 `str` 문자 '0'으로 값 채우기
     baskets = [i for i in range(N)] # N개 원소를 가진 배열에 `int` index 번호로 값 채우기
  • List 를 문자열로 바꾸기 (단, 원소의 타입이 str이여야 join이 가능함)

     baskets = [str(i) for i in range(3)] # ['0','1','2']
     print(' '.join(baskets)) # '0 1 2'
  • List 특정 index 값 수정하기

     baskets[0] = 3 # index 0 의 값을 3으로 수정하기
  • List index 위치 변경하기

     baskets = [str(i) for i in range(3)] # ['0','1','2']
     baskets[0], baskets[1] = baskets[1], baskets[0] # baskets index 0과 1 값 변경하기
     print(baskets) # ['1','0','2']
  • List 값으로 index 위치 찾기 ( 값이 없을 경우, ValueError 발생 )
    list.index(value, start, stop)

     answer = [1,2,3]
     try:
     	print(answer.index(3))	# 2
     	print(answer.index(4))	# ValueError 발생
     except ValueError:
     	answer.append(4)	# 값이 없으면, answer list에 값 추가
  • List 값 뒤집는 방법 1: Slicing Revercse
    list[::-1]

     answer = [1,2,3]
     print(answer [::-1]) # [3,2,1]
  • List 값 뒤집는 방법 2: reverse 함수
    list.reverse()

     answer = [1,2,3]
     print(answer.reverse()) # None
     print(answer) # [3,2,1]
  • List 값 뒤집는 방법 3: reversed 함수
    reversed(list)

     answer = [1,2,3]
     print(reversed(answer)) # [3,2,1]
     print(answer) # [1,2,3]
@letsjo letsjo added the STEP 단계 label Mar 29, 2023
@letsjo letsjo self-assigned this Mar 29, 2023
letsjo added a commit that referenced this issue Mar 29, 2023
letsjo added a commit that referenced this issue Mar 29, 2023
letsjo added a commit that referenced this issue Mar 29, 2023
letsjo added a commit that referenced this issue Mar 29, 2023
letsjo added a commit that referenced this issue Mar 29, 2023
letsjo added a commit that referenced this issue Mar 30, 2023
letsjo added a commit that referenced this issue Mar 30, 2023
letsjo added a commit that referenced this issue Mar 30, 2023
letsjo added a commit that referenced this issue Mar 30, 2023
letsjo added a commit that referenced this issue Mar 30, 2023
letsjo added a commit that referenced this issue Mar 30, 2023
마지막 결과값 출력을 잘못 저장하고 커밋하여 맞게 수정 후 재 커밋
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
STEP 단계
Projects
None yet
Development

No branches or pull requests

1 participant