Python/Python Programming
[Python] 반복가능 (iterable)한 객체 오른쪽(right) 순회
Pydole
2018. 5. 13. 14:54
# 스텝 슬라이싱(step slicing) 을 이용한 순회
lst = ['a','b','c','d','e','f','g']
for i in lst[::-1]:
print(i, end= ' ')
g f e d c b a
# list pop 메소드를 이용한 순회
lst = ['a','b','c','d','e','f','g']
while True:
try:
print(lst.pop(), end=' ')
except IndexError:
break
g f e d c b a