Guidelines

객체의 μˆœμ„œλ₯Ό μ—­μˆœμœΌλ‘œ λ’€μ§‘λŠ” 방법

reversed ν•¨μˆ˜λŠ” λ¦¬μŠ€νŠΈμ™€ 같은 반볡 κ°€λŠ₯ν•œ 객체의 μˆœμ„œλ₯Ό μ—­μˆœμœΌλ‘œ λ’€μ§‘μŠ΅λ‹ˆλ‹€.


reversed ν•¨μˆ˜ μ‚¬μš©λ²•

reversed ν•¨μˆ˜λŠ” 원본 리슀트λ₯Ό λ³€κ²½ν•˜μ§€ μ•Šκ³ , μ—­μˆœμ˜ μˆœμ„œλ₯Ό 가진 μƒˆλ‘œμš΄ 반볡자(iterator)λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.

반볡자(iterator)λŠ” μ»¬λ ‰μ…˜(예: 리슀트, νŠœν”Œ, λ¬Έμžμ—΄) λ‚΄μ˜ μš”μ†Œλ“€μ„ ν•˜λ‚˜μ”© 순차적으둜 μ ‘κ·Όν•  수 μžˆλŠ” 객체λ₯Ό λœ»ν•©λ‹ˆλ‹€. λ‹€μŒ μš”μ†Œλ₯Ό λ°˜ν™˜ν•˜λŠ” next() λ©”μ„œλ“œλ₯Ό 가지고 μžˆμŠ΅λ‹ˆλ‹€.


reversed ν•¨μˆ˜ μ˜ˆμ‹œ
numbers = [1, 2, 3, 4, 5] # numbers의 μ—­μˆœμΈ μƒˆλ‘œμš΄ 반볡자λ₯Ό 생성 for number in reversed(numbers): print(number) # 좜λ ₯ κ²°κ³Ό: 5, 4, 3, 2, 1

reversed ν•¨μˆ˜λŠ” λ¦¬μŠ€νŠΈλ‚˜ λ¬Έμžμ—΄ λ“± 객체 λ‚΄ μš”μ†Œμ˜ μˆœμ„œλ₯Ό λ’€μ§‘κ±°λ‚˜, λ°˜λ³΅λ¬Έμ—μ„œ μš”μ†Œλ“€μ„ μ—­μˆœμœΌλ‘œ μ²˜λ¦¬ν•  λ•Œ μ‚¬μš©ν•©λ‹ˆλ‹€.

reversed μ‚¬μš© μ˜ˆμ‹œ
numbers = [1, 2, 3, 4, 5] reversed_list = list(reversed(numbers)) print("reversed_list:", reversed_list) # [5, 4, 3, 2, 1]
Mission
0 / 1

reversed ν•¨μˆ˜λŠ” λ¦¬μŠ€νŠΈμ—λ§Œ μ‚¬μš©ν•  수 μžˆλ‹€.

O
X

Guidelines

AI Tutor

Publish

Design

Upload

Notes

Favorites

Help

Code Editor

Run
Generate

Execution Result