Skip to content

Commit f4550fa

Browse files
committed
Create print_recursively.py
1 parent 856fff5 commit f4550fa

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

print_recursively.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
def print_recursively(lst):
2+
""" Print items in the list, using recursion.
3+
4+
>>> print_recursively([1, 2, 3])
5+
1
6+
2
7+
3
8+
"""
9+
10+
if not lst:
11+
return
12+
13+
print lst[0]
14+
15+
print_recursively(lst[1:])
16+
17+
18+
if __name__ == '__main__':
19+
import doctest
20+
results = doctest.testmod()
21+
22+
if results.failed == 0:
23+
print "ALL TESTS PASSED"

0 commit comments

Comments
 (0)