Guidelines

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

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


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

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

  • λ°˜λ³΅μžλž€? : 반볡자(iterator)λŠ” μ»¬λ ‰μ…˜(예: 리슀트, νŠœν”Œ, λ¬Έμžμ—΄) λ‚΄μ˜ μš”μ†Œλ“€μ„ ν•˜λ‚˜μ”© 순차적으둜 μ ‘κ·Όν•  수 μžˆλŠ” 객체둜, λ‹€μŒ μš”μ†Œλ₯Ό λ°˜ν™˜ν•˜λŠ” next() λ©”μ„œλ“œλ₯Ό 가지고 μžˆμŠ΅λ‹ˆλ‹€.
reversed ν•¨μˆ˜ μ˜ˆμ‹œ
numbers = [1, 2, 3, 4, 5] for number in reversed(numbers): # 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]

Guidelines

AI Tutor

Publish

Design

Upload

Notes

Favorites

Help

Code Editor

Run
Generate

Execution Result