Python Exercise Example 73
**Problem:** Output a linked list in reverse.
**Analysis:** None.
Example (Python 2.0+)
#!/usr/bin/python
-- coding: UTF-8 --
if
name
==
'
main
'
:
ptr
=
[
]
for
i
in
range
(
5
)
:
num
=
int
(
raw_input
(
'
please input a number:
\n
'
)
)
ptr
.
append
(
num
)
ptr
ptr
.
reverse
(
)
ptr
The output of the above example is:
please input a number:
6
please input a number:
5
please input a number:
3
please input a number:
4
please input a number:
8
[6, 5, 3, 4, 8]
[8, 4, 3, 5, 6]
Python 100 Examples